Set FORM field value based on value of another field
Posted on 2001-08-28
Here's what I need:
A small javascrip application, as horizontally-compatible as possible (with any details of browsers/situations where it may not be compatible and why) that will set the value of one field in a FORM based on the value of another field. And a variation that can set the value of one field to equal the value of another field plus some additional text.
I want to know all the ways this script can be executed, i.e. do I have to put a reference in the FORM or submit button or is there a way to have it function automatically by embedding the script at different points in the html page?
<form method="post" action="...">
<option value="a">First Option
<option value="2">Second Option
... (more stuff)
I'd like examples of ways a hidden field, say like:
<input type="hidden" name="fieldAdesc" value="..">
can be set to:
"First Option" if fieldA="a"
"Second Option" if fieldA="2"
and how in which this can be done... only upon submit, in real time to change the field value at the time of selecting the pulldown - etc? Ideally, it would be nice to have the script set the field value when the pulldown is selected - and can this be done without changing the FORM or SUBMIT references?
Thanks in advance for your assistance. Extra good kharma will also be awarded to the person with the most complete answer!