acctman Posted April 29, 2009 Share Posted April 29, 2009 i'm using this script code, i need to use the form field id's instead of the name. how can I do that? <script type="text/javascript"> function validate(form) { var city = form.city.value; var zip = form.zip.value; if(city == "") { inlineMsg('city','<strong>Error:</strong><br />Enter your city.',6); return false; } if(zip == "") { inlineMsg('zip','<strong>Error:</strong><br />Enter your US or CAN Zip.',6); return false; } return true; } </script> Link to comment https://forums.phpfreaks.com/topic/156205-solved-user-form-id-instead-of-form-name/ Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 ??? Sorry, I'm not following. Link to comment https://forums.phpfreaks.com/topic/156205-solved-user-form-id-instead-of-form-name/#findComment-822350 Share on other sites More sharing options...
acctman Posted April 30, 2009 Author Share Posted April 30, 2009 ??? Sorry, I'm not following. form.city.value; looks for the form field with "name=city" in it. i'd like for it to look for the "id" instead, since I have other code that requires the form field name to be formated a name=add[city] in which the javascript can not detect. i tried changing form.city.value to document.getElementById(city) and putting id=city in the form input code but that didn't work Link to comment https://forums.phpfreaks.com/topic/156205-solved-user-form-id-instead-of-form-name/#findComment-822354 Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 <script type="text/javascript"> function validate(form) { var city = form.getElementById("city").value; var zip = form.getElementById("zip").value; if(city == "") { inlineMsg('city','<strong>Error:</strong><br />Enter your city.',6); return false; } if(zip == "") { inlineMsg('zip','<strong>Error:</strong><br />Enter your US or CAN Zip.',6); return false; } return true; } </script> Link to comment https://forums.phpfreaks.com/topic/156205-solved-user-form-id-instead-of-form-name/#findComment-822357 Share on other sites More sharing options...
acctman Posted April 30, 2009 Author Share Posted April 30, 2009 <script type="text/javascript"> function validate(form) { var city = form.getElementById("city").value; var zip = form.getElementById("zip").value; if(city == "") { inlineMsg('city','<strong>Error:</strong><br />Enter your city.',6); return false; } if(zip == "") { inlineMsg('zip','<strong>Error:</strong><br />Enter your US or CAN Zip.',6); return false; } return true; } </script> thanks that worked, but i had to use document. instead of form. Link to comment https://forums.phpfreaks.com/topic/156205-solved-user-form-id-instead-of-form-name/#findComment-822377 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.