function checkForm() { var flgError = 0; var errorMsg = ""; try { if( document.edit.username.value == "" ) { alert("Hello"); errorMsg+= "username cannot be left blank.\n"; document.edit.username.focus(); } if( document.edit.public_name.value == "" ) { alert("Hmm"); errorMsg+= "public_name cannot be left blank.\n"; document.edit.public_name.focus(); } if( document.edit.firstname.value == "" ) {
errorMsg+= "firstame cannot be left blank.\n"; document.edit.firstname.focus(); } if( document.edit.lastname.value == "" ) { errorMsg+= "lastname cannot be left blank.\n"; document.edit.lastname.focus(); } if( document.edit.email.value == "" ) { errorMsg+= "email cannot be left blank.\n"; document.edit.email.focus(); } if( document.edit.password.value == "" ) { alert("Hrrm"); errorMsg+= "password cannot be left blank.\n"; document.edit.password.focus(); } if( errorMsg != "" ) { alert(errorMsg); return false; }
return true; }
It goes in here just fine, but it doesn't work. Putting an Alert before the last if is ignored it seems to only bother checking the first 2 ifs and then jumps over to return true its not making any sense.
IP: Logged |
quote:Originally posted by Blayne Bradley: Ignore the Try {
I can do so, but surely even you cannot possibly believe that the Javascript engine will?
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
Blayne Bradley
unregistered
posted
No, you do not understand, that is an error in COPYING to Hatrack, in reality the script I am playing with does not have the try/catch code at all. Hench it is not the problem.
IP: Logged |
posted
So not only do you bring Hatrack trivial problems which you proceed to solve in five minutes, you can't even copy your code correctly and make it possible for us to diagnose it? Dude, this is kindergarten stuff. Sharpen up.
Posts: 10645 | Registered: Jul 2004
| IP: Logged |
Blayne Bradley
unregistered
posted
I assure you a spent a good hour on it before posting.
IP: Logged |
posted
Looking at the code, and trying to guess what you're trying to accomplish, I'm assuming you just discovered the benefit of using "else"...
Posts: 3486 | Registered: Sep 2002
| IP: Logged |
quote:posted by Blayne: Javascript Woes, its ignoring my ifs!
Well so long as your "ands" and "buts" are still functional, you aren't out of options yet.
Posts: 21898 | Registered: Nov 2004
| IP: Logged |
Blayne Bradley
unregistered
posted
no the point is is that if there are MANY blank fields then the popup alert will display all of the blank fields to inform the user, having else's would only show one. The problem I figured out was that there was a syntax error in the javascript which it turns out I didnt notice until I posted, the variable names for firstName and lastName were wrong in my JS and didnt match the names of the html fields.
IP: Logged |