Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can JS pass a form SELECT value to a form HIDDEN value?

Status
Not open for further replies.

Overspeed

Programmer
Jul 10, 2007
15
CA
Hello,

I have a form with a <select> field named "shipping" which has 3 options. I need to add a hidden field type that will somehow grab the value of "shipping" and assign it to the hidden field "shipping2" when submitted. Seen below:

<select id="shipping" name="shipping">
<option value="15.00">Canada</option>
<option value="25.00">United States</option>
<option value="35.00">International</option>
<select>
<input type="hidden" name="shipping2" id="shipping2" value="">

Basically this is for a PayPal Cart where I need to specify both "shipping" and "shipping2". "shipping" is the base cost for a single item and "shipping2" is for each additional item added. I can't really add a second <select> field asking for the same input so I'm hoping that somehow JS can pass the value of "shipping" to "shipping2" during submit. Thank you much.

Hugz

Jenny
 
Figured it out:

function applyShipping() {
document.getElementById('shipping2').value = document.getElementById('shipping').value;
}

<form onSubmit="applyShipping()">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top