Javascrip code in php variable

Discussion in 'Javascript' started by Dan, Nov 23, 2005.

  1. Dan

    Dan Guest

    Hi,

    I would like to know if it is possible to insert workable javascript
    code into a variable. For example, in php if I say

    <? echo $blah; ?> and $blah equals " ?> <script>
    top.navi.document.title </script> <?"

    I would want the page to act out the code when i tell it to echo the
    variable.

    If this is not possible, is there a way to set information from
    javascript into a php variable?

    Also, i would like to know how to use if statements in javascript. For
    example, if I have a variable x and i want to see if x equals "test"
    and if it does then it caries out some code.

    Thanks
    Dan
    Dan, Nov 23, 2005
    #1
    1. Advertising

  2. Dan

    Randy Webb Guest

    Dan said the following on 11/23/2005 6:57 PM:
    > Hi,
    >
    > I would like to know if it is possible to insert workable javascript
    > code into a variable. For example, in php if I say
    >
    > <? echo $blah; ?> and $blah equals " ?> <script>
    > top.navi.document.title </script> <?"
    >
    > I would want the page to act out the code when i tell it to echo the
    > variable.


    Did you test it?

    > If this is not possible, is there a way to set information from
    > javascript into a php variable?


    Before anybody points it out, I am referring to client-side Javascript
    and native Server Side PHP.

    PHP is server side. It is executed before the browser ever sees it.
    JS is client side. It is executed after the browser gets it.
    They do not interact without another call to the server.

    > Also, i would like to know how to use if statements in javascript. For
    > example, if I have a variable x and i want to see if x equals "test"
    > and if it does then it caries out some code.


    if (condition){
    //statements if condition is true
    }
    else{
    //statements if condition is false
    }
    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Nov 24, 2005
    #2
    1. Advertising

  3. Dan wrote:

    > I would like to know if it is possible to insert workable javascript
    > code into a variable. For example, in php if I say
    >
    > <? echo $blah; ?> and $blah equals " ?> <script>
    > top.navi.document.title </script> <?"


    That would be parsed into

    ?> <script>
    top.navi.document.title </script> <?

    > If this is not possible, is there a way to set information from
    > javascript into a php variable?


    Yes, there is. See
    news: and the
    following thread.

    > Also, i would like to know how to use if statements in javascript.
    > For example, if I have a variable x and i want to see if x equals
    > "test" and if it does then it caries out some code.


    if (x == "test")
    {
    // ...
    }


    PointedEars
    Thomas 'PointedEars' Lahn, Nov 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Ladd

    Disable Calendar Control from javascrip

    Robert Ladd, Feb 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,268
    Robert Ladd
    Feb 27, 2005
  2. =?utf-8?B?4pmlZVh0cmVtZSBvWHlnZW7imaU=?=

    How do i call JAVASCRIP function if...

    =?utf-8?B?4pmlZVh0cmVtZSBvWHlnZW7imaU=?=, Aug 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    477
    =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmE=?=
    Aug 25, 2006
  3. Ganesh
    Replies:
    1
    Views:
    442
    clintonG
    Aug 2, 2007
  4. Rajive Narain
    Replies:
    0
    Views:
    1,718
    Rajive Narain
    Sep 18, 2009
  5. cz
    Replies:
    4
    Views:
    760
    Eric Christopherson
    Feb 15, 2011
Loading...

Share This Page