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> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 ??? Sorry, I'm not following. Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.