I'm using JavaScript to validate information on a form prior to submission and I've run into a snag. One field on the form is for an order number which must begin with the letter 'n' (either upper or lower case). I'm using the following code to check for the leading 'n' using onSubmit to access the function:
if(document.forms[0].ord_nbr.value.charAt(0) != n) {
alert("......"
return false;
}
I've tried surrounding the 'n' on the right side of the comparison with single quotes, double quotes, parenthesis and nothing seems to work. I know there must be a simple solution to this.
Using another alert, I can see that the charAt() method is catching the correct value for the first character in the field.
Thanks, JS newbie
if(document.forms[0].ord_nbr.value.charAt(0) != n) {
alert("......"
return false;
}
I've tried surrounding the 'n' on the right side of the comparison with single quotes, double quotes, parenthesis and nothing seems to work. I know there must be a simple solution to this.
Using another alert, I can see that the charAt() method is catching the correct value for the first character in the field.
Thanks, JS newbie