[thelist] php question - changing one form value based on select choice
Erik Mattheis
gozz at gozz.com
Mon Oct 17 20:40:28 CDT 2005
You would do this with JavaScript, but it would be much wiser to come
up with $price on the fly in your form processing template.
To do it with JavaScript, (if you must):
function changePrice(form) {
if(form.Size.options[form.menu.selectedIndex].value == 'Large') {
form.hiddenprice.value = 10;
}
else if(form.Size.options[form.menu.selectedIndex].value == 'Small') {
form.hiddenprice.value = 8;
}
}
<select name="Size" onchange="changePrice(this.form)>
<option value"Large" selected="selected">Large</option>
<option value"Small">Small</option>
</select>
<input type="hidden" name="hiddenprice" value="10" />
To do it server-side with PHP, just set up a conditional that assigns
the correct value to $price based on the value of $_FORM['Size'].
On Monday, October 17, 2005, at 08:04 PM, Jeniffer C. Johnson wrote:
> I think this might possible, but can't think of how to do it (and
> can't find
> an accurate search phrase). What I want is to have a form with a select
> list, and based on which option is selected, to send a specific hidden
> value
> with the other values when the form is submitted. So if, for example,
> Large
> is selected from the Size list, then a hidden field giving price of
> $10 is
> sent, but if Small is selected, then the hidden field is sent assigning
> price of $8.00.
--
- Erik Mattheis
612 377 2272
http://gozz.com/
More information about the thelist
mailing list