www.webdeveloper.com
Results 1 to 3 of 3

Thread: Passing variable value to another page

  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Passing variable value to another page

    I have an external javascript file (calculate.js) which calculates the price of a product, based on a users preferences in a form (dropdowns, radio buttons etc). The script then displays the price on the page (index.html) using:

    document.getElementById("price").innerHTML = price;

    Once the user has finished making their choices, they then click the forms submit button (method="post") to be taken to a confirmation page (confirm.php).

    Here, I can display the users preferences using php code like:

    <?php echo $_POST['size'] ?>
    <?php echo $_POST['color'] ?>
    etc, etc...

    But I'm not sure how to pass the price over!!!!

    The preferences come from the form and are picked up with php.
    But the price is calculated with javascript! How do I send it to confirm.php?

    Can I add a hidden input to index.html with the value set as the javascript variable called price? If so, what syntax do I use for this? I have tried

    document.write('<input type="hidden" name="quote" value="'price'" ?>" />')

    and some other stuff too, but I still can't get it to work!

    Or do I pass the value in the url, like confirm.php?Quote='price'?
    Again, what is the syntax, as I can't seem to get it to work?

    Any help would be great. Thanks.

    MetaName

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by MetaName View Post
    I have an external javascript file (calculate.js) which calculates the price of a product, based on a users preferences in a form (dropdowns, radio buttons etc). The script then displays the price on the page (index.html) using:

    document.getElementById("price").innerHTML = price;

    Can I add a hidden input to index.html with the value set as the javascript variable called price? If so, what syntax do I use for this? I have tried

    document.write('')


    html:
    Code:
    <input type="hidden" id="price2"  />
    js:
    Code:
    document.getElementById("price").innerHTML = price;
    document.getElementById("price2").value= price;

  3. #3
    Join Date
    Dec 2009
    Posts
    2
    That did the job perfectly.

    Thank you.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles