Forum Moderators: open

Message Too Old, No Replies

javascript check before posting the form with botdetect

checking if the input is correct.

         

fototex

1:48 pm on Jul 18, 2009 (gmt 0)

10+ Year Member



Hi everybody,

I have an .asp page for my customers which does just accepts e-mail information and passes this information to another .asp page. But before passing the info, a javascript checks whether the entered e-mail does match some certain rules.

Rule1: If any input has been made at all,
Rule2: If an "@" sign is there, if the"." is there and so on.

upon pressing the submit button, the first rule works but the second rule does not. Could not figure it out why.

Here is the code. :
----------------------------------------------

<html>
<!-- #include file="include/common.asp" -->
<head>
<link type='text/css' rel='Stylesheet' href='http://localhost/FormStyle.css' />
<script type="text/javascript" src="BotDetectScript.js"></script>
</head>

<SCRIPT SRC="language-tr.js"></SCRIPT>
<SCRIPT src="mainscript.js"></SCRIPT>

<script language="javascript">

if (top.frames['mainsubframe'] == undefined){
window.location.href = "index.htm";
}

function control()
{
if (document.SampleForm.Email.value == ""){
alert("Please enter your e-mail address.");
document.SampleForm.Email.focus();
return false;
}

//if (!isValidEmail(document.forms[0].Email)) return false;
//document.forms[0].submit();

}
function isValidEmail(obj)
{
if (obj.value.indexOf ('@',0) == -1 ¦¦ obj.value.indexOf ('.',0) == -1 ¦¦ obj.value == "")
{
alert("Invalid e-mail address. Please check again.");
obj.select();
obj.focus();
return false;
}
return true;
}

</script>

<body>
<form name="SampleForm" id="SampleForm" method="post" action="sendpassword.asp">
<fieldset id="SampleFields">
<legend>Sample input form</legend>
<div class="input">
<label for="Email">E-mail&nbsp;&nbsp;&nbsp;&nbsp; address</label>
<input name="Email" id="Email" type="text" class="textbox" value="" size="20" value="<% =Request("Email") %>"/>
</div>
</fieldset>
<fieldset id="CaptchaValidation">
<legend>CAPTCHA Validation</legend>
<div id="PromptDiv">Retype the code from the picture</div>
<div id="CaptchaDiv">
<div id="CaptchaImage">
<img id="SampleForm_CaptchaImage" src="http://localhost/LanapBotDetectHandler.asp?Command=CreateImage&TextStyle=2&ImageWidth=150&imageHeight=50&CodeLength=5&CodeType=0" alt='CAPTCHA Code Image' />
</div>

<div id="CaptchaIcons">
<a href='LanapBotDetectHandler.asp?Command=CreateSound' onclick='LBD_LoadSound("SampleForm_SoundPlaceholder", "LanapBotDetectHandler.asp?Command=CreateSound");return false;' title="Speak the code"><img src="speaker.gif" alt="Speak the code" /></a>
<a href='#' onclick='LBD_ReloadImage("SampleForm_CaptchaImage"); return false;' title="Change the code"><img src="reload.gif" alt="Change the code" /></a>
<div id='SampleForm_SoundPlaceholder' class="placeholder">&nbsp;</div>
</div>
</div>

<div class="input">
<label for="CaptchaCode">Code:</label>
<input name="CaptchaCode" id="CaptchaCode" type="text" class="textbox" onkeyup="this.value = this.value.toLowerCase();" size="20" />
</div>

</fieldset>
<div id="ActionDiv">
<input type="submit" name="ProcessForm" value="Process Form" id="ProcessForm" onclick="return control()";>
</div>
</form>
</body>
</html>

-----------------------------------------------

It is the function control() which validates the e-mail field. But it just validates whether the e-mail has been entered or not. The second check (with the @ sign) is not being made.
Thanks for all your comments.

fototex

10:27 am on Jul 19, 2009 (gmt 0)

10+ Year Member



it did work with the following:

function control() {

if (document.SampleForm.Email.value == "") {
alert("Please enter your e-mail address.");
document.SampleForm.Email.focus();
return false;
}

return isValidEmail(document.forms[0].Email);
}

whoisgregg

5:16 pm on Jul 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted, fototex. :)