Hi all,
I'm required to validate a form which (for really stupid and unchangeable reasons) has to use method=get. The code I have right now submits the form even if the values are invalid, which is not what I want to have happen.
code on jstest.html:
In case you hadn't gleaned it from my onClick event, I want it to validate the strings and only submit the form if the strings pass all tests; otherwise, it just sits there like a lump and lets the user try again.
Anyone have any thoughts on what I might be doing wrong?
Thanks!
Inger
I'm required to validate a form which (for really stupid and unchangeable reasons) has to use method=get. The code I have right now submits the form even if the values are invalid, which is not what I want to have happen.
code on jstest.html:
Code:
<table align=center><tr><td align=left style="font-size:13px; color:green;">
<b>Alpha numeric Testing :</b> <br>
Enter a character / string and test it<br>
<form name="test" method=get action="jstest2.html">
<script language=javascript>
function checkit(alphane,alphanf)
{
// 1. check the first string.
var numaric = alphane;
var alphacheck = 0;
// 1A. check to make sure every character is [A-Z], [0-9]
for(var j=0; j<numaric.length; j++) {
var alphaa = numaric.charAt(j);
var hh = alphaa.charCodeAt(0);
if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123)) {
} else {
alphacheck = alphacheck + 1;
}
}
// 1B. now look for string length
if (alphacheck == 0) {
if (numaric.length <= 9 || numaric.length >= 17) {
alphacheck = alphacheck + 1;
}
}
if (alphacheck > 0) {
var alerterror = "Invalid Serial Number. Please try again.";
} else {
// 2. assuming that the first string is good,
// compare the second string to the first string to make sure they match.
var string1 = alphane;
var string2 = alphanf;
if (string1 != alphanf) {
var alerterror = "Serial numbers do not match. Please try again."
}
}
// 3. If there's an error, throw it.
if (alerterror) {
window.alert(alerterror);
return false;
} else {
return true;
}
}
</script>
<input name=u11 type=text> [ e.g: <b>alfha</b> or <b>alp#num</b>]<br>
<input name=u1a type=text> [ e.g: <b>alfha</b> or <b>alp#num</b>]<br>
<input type=submit value=validate onClick="javascript:checkit(test.u11.value,test.u1a.value);">
</form>
</td></tr></table>
In case you hadn't gleaned it from my onClick event, I want it to validate the strings and only submit the form if the strings pass all tests; otherwise, it just sits there like a lump and lets the user try again.
Anyone have any thoughts on what I might be doing wrong?
Thanks!
Inger