Javascript Errors -
08-20-2004
, 02:15 PM
Hi All,
what's wrong with this code..? After entering the code where I create
invalid characters, after the 4th return false, any code put into the page
after it, and including it, doesn't work. Little lost. Cheers.
P.S. Am studying Javascript and got this sample from a book, although, a
little different than the book's code.
downdogWoof...
<script language = "Javascript" type = "text/javascript">
<!-- Hide
function validEmail(memForm) {
if (memForm.memPassword.value == "") {
alert("You must enter a password")
memForm.memPassword.focus()
memForm.memPassword.select()
return false
}
if (memForm.memPassword.value != memForm.memPassword2.value) {
alert("Please make sure your password matches")
memForm.memPassword.focus()
memForm.memPassword.select()
return false
}
if(memForm.memUsername.value == "") {
alert("Please enter a Username")
memForm.memUsername.focus()
memForm.memUsername.select()
return false
}
if(memForm.memEmail.value=="") {
alert("Please enter an Email address")
memForm.memEmail.focus()
memForm.memEmail.select()
return false
}
var invalidChar="/;:@" //Invalid Character code
for(i=0;i<invalidChar.length;i++) {
var badChar=invalidChar.charAt(i)
if(memForm.memEmail.indexOf(badChar,0)>-1) {
alert("Your email contains bad cahracters, please try again")
memForm.memEmail.focus()
memForm.memEmail.select()
return false
}
}
if(memForm.memFName.value=="") { //this code also didn't work after
entering below the invalid character code above
alert("Please enter your 1st name")
memForm.memFName.focus()
memForm.memFName.select()
return false
}
return true
}
// End Hiding Script-->
</script> |