codenewb
11-24-2012, 09:46 PM
Hey guys, I have been working on a problem for school and we made an html form and are now using js functions to validate the form and send it to a server. It includes an address and i wanted to know how to error check to see if a person entered a valid state code(both capital letters).
I have a function now that I thought might work but I cant get it to work properly.
:code:
function checkForState() {
if (document.forms[0].state_registration.value != AK || AL || AR || AZ || CA || CO || CT || DC || DE || FL || GA || HI || IA || ID || IL || IN || KS || KY || LA || MA || MD || ME || MI || MN || MO || MS || MT || NB || NC || ND || NH || NJ || NM || NV || NY || OH || OK || OR || PA || RI || SC || SD || TN || TX || UT || VA || VT || WA || WI || WV || WY) {
window.alert("You did not enter a valid state code! Both letters must be capital!");
}
document.forms[0].state_registration.focus();
}
:code:
Does anyone have a way to do this that I am not thinking of? or did I just make a mistake? Any help or advice is appreciated thanks!
I have a function now that I thought might work but I cant get it to work properly.
:code:
function checkForState() {
if (document.forms[0].state_registration.value != AK || AL || AR || AZ || CA || CO || CT || DC || DE || FL || GA || HI || IA || ID || IL || IN || KS || KY || LA || MA || MD || ME || MI || MN || MO || MS || MT || NB || NC || ND || NH || NJ || NM || NV || NY || OH || OK || OR || PA || RI || SC || SD || TN || TX || UT || VA || VT || WA || WI || WV || WY) {
window.alert("You did not enter a valid state code! Both letters must be capital!");
}
document.forms[0].state_registration.focus();
}
:code:
Does anyone have a way to do this that I am not thinking of? or did I just make a mistake? Any help or advice is appreciated thanks!