paramjeetgemini
03-30-2009, 05:01 PM
Hello,
As you might already know that I am not a great programmar. Thas why requesting help here.
I am trying to do this:
I have a Web Form. Simple HTML Form.
I am trying to validate 2 things in this:
1. Valid E-mail through one Javascript function
2. Javascript Maths Captcha, so that there should be lesser SPAM in Form.
Following is JavaScript Code:
Code for E-mail Validation
<script type="text/javascript">
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}
</script>
Code for Maths Captcha:
<script type="text/javascript">
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 10);
var c = a + b
function DrawBotBoot()
{
document.write("What is "+ a + " + " + b +" ? ");
document.write(" <input id='BotBootInput' type='text' maxlength='2' size='2' name='hvf'/>");
}
function ValidBotBoot(){
var d = document.getElementById('BotBootInput').value;
if (d == c) return true;
(alert("Wrong Code"));
document.getElementById('BotBootInput').focus();
return false;
}
</script>
I need to call both these function with the submit button of the form:
At one time only one functions seems to work, like the below mentioned works only for Captcha, but when I add onClick event for E-mail validation as well, only one of either functions work
<input type="submit" value="Submit" name="B1" onClick="return ValidBotBoot();" />
I tried it doing this way
<input type="submit" value="Submit" name="B1" onClick="return ValidBotBoot();onClick="return checkmail(this.form.email);" />
But only one function works which is called first in onclick even in Submit button.
Can you please help me ?
As you might already know that I am not a great programmar. Thas why requesting help here.
I am trying to do this:
I have a Web Form. Simple HTML Form.
I am trying to validate 2 things in this:
1. Valid E-mail through one Javascript function
2. Javascript Maths Captcha, so that there should be lesser SPAM in Form.
Following is JavaScript Code:
Code for E-mail Validation
<script type="text/javascript">
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}
</script>
Code for Maths Captcha:
<script type="text/javascript">
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 10);
var c = a + b
function DrawBotBoot()
{
document.write("What is "+ a + " + " + b +" ? ");
document.write(" <input id='BotBootInput' type='text' maxlength='2' size='2' name='hvf'/>");
}
function ValidBotBoot(){
var d = document.getElementById('BotBootInput').value;
if (d == c) return true;
(alert("Wrong Code"));
document.getElementById('BotBootInput').focus();
return false;
}
</script>
I need to call both these function with the submit button of the form:
At one time only one functions seems to work, like the below mentioned works only for Captcha, but when I add onClick event for E-mail validation as well, only one of either functions work
<input type="submit" value="Submit" name="B1" onClick="return ValidBotBoot();" />
I tried it doing this way
<input type="submit" value="Submit" name="B1" onClick="return ValidBotBoot();onClick="return checkmail(this.form.email);" />
But only one function works which is called first in onclick even in Submit button.
Can you please help me ?