PDA

View Full Version : Combining two Javascript Functions for onClick Event



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("&nbsp;&nbsp;&nbsp;<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 ?

vinothstce
03-31-2009, 09:55 AM
hi boss i think the problem is the submit button, there is some default behaviour of a submit button by which u can submit a form and u r trying to change the functionality then how it will works, first change the submit button type to button and then call a function within which u should call the two function u need