Results 1 to 2 of 2

Thread: Combining two Javascript Functions for onClick Event

  1. #1
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Combining two Javascript Functions for onClick Event

    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
    Code:
    <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:
    Code:
    <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

    Code:
    <input type="submit" value="Submit" name="B1" onClick="return ValidBotBoot();" />
    I tried it doing this way
    Code:
    <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 ?

  2. #2
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •