Link to home
Start Free TrialLog in
Avatar of pnoeric
pnoericFlag for United States of America

asked on

get value for form field

See sample code below-- note two forms with identically named 'phone number' fields. In JS, I want to get the value for 'phone' from the form that the user submitted. (This is a small example -- I have dozens of fields in the real forms... so I don't want to give every single field in each form its own unique ID.)
<form id='form1'>
   phone number: <input name='phone'>
   <input type='submit' onClick="validate('form1');">
</form>
 
<form id='form2'>
   phone number: <input name='phone'>
   <input type='submit' onClick="validate('form2');">
</form>
 
 
then in the JS...
 
<script>
 
function validate(f) {
   // note that f == 'form1' or 'form2'
   // how do I get the value of the 'phone' field from the form the user submitted?
   // I'm using the Prototype library, if it helps...
}
 
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jonah11
Jonah11

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
document.f.phone.value

i believe
Avatar of Jonah11
Jonah11

dvz, that won't work because he's passing in the string name for the form.
jonah, ah thanks for the correction.