Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Thanked 0 Times in 0 Posts

    Unhappy Passing variables between js and php

    Hey people. I'm new here, and I was wondering if anyone could help me. I have just started learning how to use PHP and JavaScript, and I wanted to assign a javascript variable to as php one. How can I go about this. Here is what I had tried but it isn't work. Can anyone help:

    function viewStudy(id)
    <? $_SESSION['studyID'] = "<script type='text/javascript'>=id;</script>" ?>;

    var url = "http://www.onlinemia.com/worklist/worklist.php";
    var win = window.open(url, 'mainFrame');
    var url1 = "http://www.onlinemia.com/OnlineMIA_JavaWebStart.jnlp";
    var win1 = window.open(url1);

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Near Chicago, IL, USA
    Thanked 32 Times in 31 Posts
    Javascript runs on the client. After the server is done with it. After PHP has run and finished.
    If you want to use a JS variable, you need to initiate another GET or POST to the server with JS and pass the variable to PHP as a GET or POST parameter.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts