Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Question Rrunning two onSubmit's at once?

    hello, i'm trying to run both of these form validation scripts at once while submitting a form, but only the first one (email validate) seems to be working,
    the other is for confirming password.

    my code:


    <script language = "Javascript">

    function echeck(str) {

    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
    alert("Please Enter a Valid E-mail Address")
    return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    alert("Please Enter a Valid E-mail Address")
    return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    alert("Please Enter a Valid E-mail Address")
    return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
    alert("Please Enter a Valid E-mail Address")
    return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    alert("Please Enter a Valid E-mail Address")
    return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
    alert("Please Enter a Valid E-mail Address")
    return false
    }

    if (str.indexOf(" ")!=-1){
    alert("Please Enter a Valid E-mail Address")
    return false
    }

    return true
    }

    function ValidateForm(){
    var emailID=document.profile.email

    if ((emailID.value==null)||(emailID.value=="")){
    alert("Please Enter your Email Address")
    emailID.focus()
    return false
    }
    if (echeck(emailID.value)==false){
    emailID.value=""
    emailID.focus()
    return false
    }
    return true
    }
    </script>


    <form name="profile" action=signup.php method=post onSubmit="return ValidateForm()" onsubmit="return checkForSamePassword(this)">


    anyone tell me what i've done wrong or need to do to fix this?

    thanks in advance for your time!
    -Ken

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    onSubmit="return ValidateForm(); return checkForSamePassword(this)">

  • #3
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    onSubmit="return (ValidateForm() && checkForSamePassword(this) )">

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    still having the same problem, only seems to run the first called function.



    <form name="profile" action=signup.php method=post onsubmit="return checkForSamePassword(this); return ValidateForm()">


    any other ideas?

    thanks again for your time!
    -Ken

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    oh thanks SpirtOfGrandeur!
    that did the trick!

    -Ken

  • #6
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    you could also make a function that calls both functions

    like


    function functiontocallinonsubmit() {
    functiontocall1()
    functiontocall2()
    }

  • #7
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried this method above.
    onSubmit="return (ValidateForm() && checkForSamePassword(this) )">
    But it is by passing all the javascript.
    The url is http://christiangamers.net/TS/TS.php

    My code
    Code:
    <form name="validation" onSubmit="return checkbae() && return checkCheckBox(this) )" form action="terms.php" method="post">
      <table width="380" border="0" align="center">
            <tr>
              <td width="146" class="style6 gen">Player Name:</td>
              <td width="224"><input type="text" name="name" /></td>
            </tr>
            <tr>
              <td><span class="style6 gen">Email</span><span class="gen">:</span></td>
              <td><input type="text" name="email" /></td>
            </tr>
            <tr>
              <td><input type="checkbox" value="0" name="agree"></td>
              <td class="style6 gen">Do you accept these terms?</td>
            </tr>
            <tr>
              <td><input name="submit" type="submit" value="Agree" /></td>
              <td>&nbsp;</td>
            </tr>
      </table>
            <p align="center" class="gen">script by <a href="http://www.christian-web-masters.com" target="_blank">iLuke</a>        </p>
    </form>
    Code:
    <script language="JavaScript1.2">
    
    //Advanced Email Check credit-
    //By JavaScript Kit (http://www.javascriptkit.com)
    //Over 200+ free scripts here!
    
    var testresults
    function checkemail(){
    var str=document.validation.email.value
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
    testresults=true
    else{
    alert("Please input a valid email address!")
    testresults=false
    }
    return (testresults)
    }
    </script>
    Code:
    <script>
    function checkbae(){
    if (document.layers||document.getElementById||document.all)
    return checkemail()
    else
    return true
    }
    </script>
    Code:
    <script language=JavaScript>
    <!--
    
    //Accept terms & conditions script (by InsightEye www.insighteye.com)
    //Visit JavaScript Kit (http://javascriptkit.com) for this script & more.
    
    function checkCheckBox(f){
    if (f.agree.checked == false )
    {
    alert('Please check the box to continue.');
    return false;
    }else
    return true;
    }
    //-->
    </script>

  • #8
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kenerly
    onSubmit="return (ValidateForm() && checkForSamePassword(this) )">
    ... and ...
    <form name="validation" onSubmit="return checkbae() && return checkCheckBox(this) )" form action="terms.php" method="post">
    The first method was correct; the second as typed inside the <form> tag is incorrect. Notice that in the former method, you are only calling 'return' once and return the value of ValidateForm() and checkForSamePassword(). Thus the second should be written:
    Code:
    <form name="validation" onSubmit="return (checkbae() && checkCheckBox(this) )" action="terms.php" method="post">
    Also, inside your <form> tag, you had an extra 'form' attribute(?) which may be causeing some confusion to the browsers (although the browsers should just be ignoring attributes they don't understand).
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #9
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Pyth007 that makes more sense...


  •  

    Posting Permissions

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