jeeves245 Posted October 21, 2009 Share Posted October 21, 2009 Hey guys i'm having a bit of trouble with a script... it's just some basic form validation but I can't get it working (I click submit and it submits even if nothing is in the text boxes). The name of the form is "form1" and in the form tags I am putting "onsubmit="return validate_form(this);" Here is the main code, which I am putting between the head tags: function validemail(email) { invalidChars = " /:,;" if (email == "") { return false; } for (i=0; i<invalidChars.length; i++) { badChar = invalidChars.charAt(i); if (email.indexOf(badChar,0) > -1) { return false; } } atPos = email.indexOf("@",1); if (atPos == -1) { return false; } if (email.indexOf("@",atPos+1) > -1) { return false; } periodPos = email.indexOf(".",atPos); if (periodPos == -1) { return false; } if (periodPos+3 > email.length) { return false; } return true; } //This function will validate a form function validateForm(form1) { if (form1.name.value == "") { alert("Please enter your name to proceed!"); form1.name.focus(); return false; } if (form1.comments.value == "") { alert("Please enter a message to proceed!"); form1.comments.focus(); return false; } if (!validemail(form1.email.value)) { alert("Please enter a correct Email address!"); form1.email.focus(); return false; } return true; } Any ideas appreciated. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 21, 2009 Share Posted October 21, 2009 Hmm... You're calling the function like so onsubmit="return validate_form(this);" And, here is the function function validateForm(form1) { //bunch of validation code } I couldn't imagine what could be wrong. Ok, I was just being sarcastic, it happens to the best of us. But, if you still don't see the problem: "validate_form" != "validateForm" Quote Link to comment Share on other sites More sharing options...
jeeves245 Posted October 22, 2009 Author Share Posted October 22, 2009 Ah.. missed that As you said, happens to the best of us. Cheers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.