#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Adelaide
    Posts
    72
    Rep Power
    14

    php and javascript


    Hi,
    I have a javascript function returning a value. I would like to know how I can use this value in my php code.

    I am using a switch statement.

    switch("") <--- i want to use that value from my javascript
    function in here !
    {
    case 1: blah blah
    }

    How can I do this??

    Thanks for any replies.......

    yoshi
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    266
    Rep Power
    14
    What I have done is use a form to set a hidden form element equal to a javascript value. Then I print out that form value in PHP.


    To take a variable from PHP I use something like


    document.value=<? print "$value"; ?>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Adelaide
    Posts
    72
    Rep Power
    14
    Could you send me an example please. It's hard to understand without an example.

    Appreciate the help.

    Regards,
    Yoshi
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    266
    Rep Power
    14
    Here you go the first is the HTML file you need, then there is a very simple php file to post to. You must first click the 'click here' then click submit.


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <HTML>
    <HEAD>
    <TITLE>Untitled</TITLE>
    <META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ ME">
    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
    function test(apply) {
    document.colorss.Form_Text_Decoration.value='test';
    }
    </SCRIPT>
    </HEAD>

    <BODY>


    <a href="#" onclick="test();">Click Here</a>

    <form method="post" name="colorss" action="css.php">
    <input type="hidden" name="Form_Text_Decoration" size="10" maxlength="6">
    <input type="submit" value="submit">
    </form>

    </BODY>
    </HTML>

    This is the PHP file.

    <?
    print "$Form_Text_Decoration";
    ?>
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Adelaide
    Posts
    72
    Rep Power
    14
    Theeggman thanks alot for your prompt reply.

    later,

    Yoshi
  10. #6
  11. No Profile Picture
    Shrill Digital God
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Raleigh, NC
    Posts
    64
    Rep Power
    14
    Thanks for the cool demonstration.

    Just fooling around, I used the onClick handler on the submit button:

    <form method="post" name="colorss" action="test.php">
    <input type="hidden" name="Form_Text_Decoration" size="10" maxlength="6">
    <input type="submit" value="submit" onClick="test();">
    </form>

    Wonder if it works with Netscape...
    I'm not impatient, I just have a low tolerance for boredom.

IMN logo majestic logo threadwatch logo seochat tools logo