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 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Onsubmit Functions

    Hello all, I have searched the forums and found posts that seem like they should solve my problem but I still cant get it working.

    Basically I am building a form that contains many checkmarks and pick lists. I need to have it so each checkmark is checked, and each pick list has a selection made before a user can submit (annoying I know but its not up to me).

    I can get one or the other to work but not all all of them. Any help would be greatly appreciated.


    Here is the code.


    onsubmit="return validateForm()&& return checkCheckBox(this)">

    Then in the <HEAD> I have:


    <SCRIPT language="JavaScript" type="text/javascript">
    <!--
    // Script Source: insighteye.com
    function checkCheckBox(f){
    if (f.agree.checked == false )
    {
    alert("You must accept the conditions to continue.");
    return false;
    }else
    return true;
    }
    //-->
    </SCRIPT>


    <SCRIPT LANGUAGE="JavaScript">
    <!--

    function validateForm(){
    if(document.form.scouting.selectedIndex==0)
    {
    alert("Please select a Specialist.");
    document.form.scouting.focus();
    return false;
    }
    return true;
    }
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="JavaScript">
    formelement.onsubmit=function(e){
    return checkCheckBox(this)&&return validateForm();
    };
    </SCRIPT>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    onsubmit="return validateForm() && checkCheckBox(this)"
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Sep 2005
    Location
    Ottawa, ON
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    do it in one function

    why not put all the checks in one validate function?

    Code:
    function validateForm(f) {
      if (!f.selectOne.selectedIndex) {
        alert('Field One is Mandetory')    
        return false;
      }
      else if (!f.checkBoxTwo.checked) {
        alert('Field Two is Mandetory')    
        return false;
        
      }
      return true;
    }

  • #4
    New Coder
    Join Date
    Feb 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you guys so much.


  •  

    Posting Permissions

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