Hello,
I am trying to incorporate the following code into an existing javascript that checks data inputted into a form.
I added a field just above the submit button on the asp form that incorporates captcha to reduce the amount of spam we are getting. The field and value is working fine. Just need a way to keep someone from getting past entering the correct value before the email is sent.
I need to add at the top somehow:
<!-- Include file for CAPTCHA form processing -->
<!-- #include file="CAPTCHA/CAPTCHA_proc
ess_form.a
sp" -->
And some kind of code to check the variable (blnCAPTCHAcodeCorrect) for a false condition and then clear the field and give the below error: (I know this is vbscript, but I do not know the javascript equivalent syntax).
If blnCAPTCHAcodeCorrect = False Then Response.Write(" CAPTCHA code is NOT correct, please press the Load New Code link and enter the new value")
End If
Here is the code that creates the field, etc in the asp form:
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td><img src="CAPTCHA/CAPTCHA_image
.asp" alt="Code Image - Please contact webmaster if you have problems seeing this image code" id="CAPTCHA" /> <a href="javascript:reloadCAP
TCHA();"><
% = strTxtLoadNewCode %></a></td>
</tr>
<tr>
<td><input type="text" name="securityCode" id="securityCode" size="12" maxlength="12" autocomplete="off" /></td>
</tr><%
Here is the working script for the form:
// <!--
function validateForm(theForm)
{
var isPhone = /^\([1-9]\d{2}\)\s?\d{3}\-
\d{4}$/; // (000)000-0000 or (000) 000-0000
var isEmail = /^[a-z][a-z0-9]*([.\-_][a-
z][a-z0-9]
*)*@([a-z]
[a-z0-9]*.
)*([a-z]{2
}|com|net|
org|biz|go
v|pro|int|
mil|edu|in
fo|name|ae
ro|coop|mu
seum)$/i;
if(theForm.Name.value.spli
t(" ").join("") == "")
{
alert("Please enter your Name.");
theForm.Name.select();
theForm.Name.focus();
return (false);
}
if(theForm.Name.value.leng
th > 70)
{
alert("Please enter at most 70 characters in the Name field.");
theForm.Name.focus();
return (false);
}
if(theForm.EmailAddress.va
lue.split(
" ").join("") == "")
{
alert("Please enter a Email Address.");
theForm.EmailAddress.selec
t();
theForm.EmailAddress.focus
();
return (false);
}
if (!isEmail.test(theForm.Ema
ilAddress.
value))
{
alert("The Email Address is NOT in the corect format.");
theForm.EmailAddress.focus
();
return (false);
}
if (theForm.EmailAddress.valu
e.length > 35)
{
alert("Please enter at most 35 characters in the Email Address field.");
theForm.EmailAddress.focus
();
return (false);
}
if (theForm.DaytimePhone.valu
e.split(" ").join("") == "")
{
alert("Please enter a Daytime Phone Number.");
theForm.DaytimePhone.selec
t();
theForm.DaytimePhone.focus
();
return (false);
}
if (!isPhone(theForm.DaytimeP
hone.value
))
{
alert("The Phone Number is NOT in the correct format:\n...(000)000-0000 or (000) 000-0000.");
theForm.DaytimePhone.focus
();
return (false);
}
if (theForm.DaytimePhone.valu
e.length > 14)
{
alert("Please enter at most 14 characters in the \"Daytime Phone\" field.");
theForm.DaytimePhone.focus
();
return (false);
}
return (true);
}
// -->
Hope this makes sense.
Thank you in advance.