Form Validation And Submit Disable

liunx

Guest
Ok, So i have a form, and im using these two functions... one of them verifies the email addy, and the other disables the submit button so you cant click it twice, i can get them to both work, but not together, im very new to JavaScript so if anyone sees what im doing wrong it would be greatly appreaciated.<br />
<br />
<br />
<SCRIPT language='javascript'><br />
function disableButton(theButton)<br />
{<br />
theButton.value="Sending...";<br />
theButton.disabled = true;<br />
theButton.form.submit();<br />
}<br />
<!--<br />
<br />
function verifyEmail(form) {<br />
checkEmail = form.email.value<br />
<br />
if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) <br />
{alert("You have entered an invalid email address. Please try again.");<br />
form.email.select();<br />
return false;<br />
} <br />
<br />
else {<br />
form.method="post";<br />
form.target="_self";<br />
form.action="mailer.php";<br />
form.submit();<br />
}<br />
}<br />
//--></script><br />
<br />
<br />
<br />
<br />
<br />
and for the form<br />
<br />
<br />
<br />
<br />
<br />
<FORM onsubmit="verifyEmail(this); return false; disableButton(this.submit); return true;"><br />
<br />
<br />
Name:<br />
<input name="name"type="text" id="name"><br><br />
Email: <br />
<input name="email" type="text" id="email"><br><br />
<br />
<TEXTAREA name="message" rows="20" cols="80"></TEXTAREA><br><br />
<INPUT TYPE="submit" VALUE="Send" name="submit" onclick="disableButton(this)"><br />
<INPUT value="Reset" type="reset"><br />
</FORM><br />
<br />
<br />
in order to get the submit button to disable i need to have the "onclick="disableButton(this)" in the submit button, but the only way i can get the email validation to work is to take it out, i really have no idea what im doing, but i think the reason it wont work is because disableButton uses "(this)" and verifyEmail uses "(this)" as well, any ideas?<br />
<br />
Thanks,<br />
~Hal<!--content-->Do not double post (in more than one forum), its considered rude!<br />
<br />
If you didn't already get it working, this should do it:<br />
<br />
<SCRIPT language='javascript'><br />
<br />
function disableButton(theButton) {<br />
theButton.value="Sending...";<br />
theButton.disabled = true;<br />
return verifyEmail(document.myForm)<br />
}<br />
<br />
function verifyEmail(form) {<br />
checkEmail = form.email.value<br />
<br />
if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) {<br />
alert("You have entered an invalid email address. Please try again.");<br />
form.email.select();<br />
form.submit.disabled = false;<br />
form.submit.value = "Send";<br />
return false;<br />
} <br />
<br />
else {<br />
return true;<br />
}<br />
}<br />
<br />
</script><br />
<br />
<FORM name="myForm" onsubmit="return disableButton(this.submit);" method="post" target="_selF" action="mailer.php"><br />
Name: <input name="name"type="text" id="name"><br><br />
Email: <input name="email" type="text" id="email"><br><br />
<TEXTAREA name="message" rows="20" cols="80"></TEXTAREA><br><br />
<INPUT TYPE="submit" VALUE="Send" name="submit"><br />
<INPUT value="Reset" type="reset"><br />
</FORM><!--content-->sorry... realized i should have posted it into the javascript forum, i thought i deleted this post...<!--content-->
 
Back
Top