View Full Version : Passing on javascript values to PHP variable?

Len Whistler
10-15-2005, 01:26 AM
The javascript code below adds values "sh" and "ww" for the text box named "shipping" and updates instantly when the user selects the location to ship to.

document.autoSumForm.shipping.value = (sh * 1) + (ww * 1);

I would like to pass that value on to a PHP variable. Can this be done?


10-15-2005, 03:08 AM
You would need to either submit the form to a php script:

<form action="yourpage.php">

or redirect to a php script using something like this:


Then in your php script use:

$input = $_REQUEST['shipping'];

The input variable would then contain the shipping value from your form.

Len Whistler
10-15-2005, 07:49 AM
Ok thanks pccode....

I got it to work with code #1 and #3. And I will look into code #2 later on. I'm building a PHP, MySQL and Javascript shopping cart from scratch.

10-19-2005, 12:57 AM
You could also store your calculated value as a 'hidden' type of input field and have it get passed along as a $_POST[] value...