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 3 of 3

Thread: return onsubmit

  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    return onsubmit

    Hi all. Please help. I have a form with a validate onsubmit like this....

    Code:
    onsubmit="return validateTracking(this) && chkFormTrack(this)"
    Why is the form trying to submit after validateTracking(this) is true. I thought the form only trys to submit after both are true?

    Here is the javascript for the validatation......

    Code:
    <script>
    
    function validateTracking(theForm){
    
    if(theForm.track_num){
          if((theForm.track_num.value == '') || (theForm.track_num.value == "Enter Tracking Number") || (theForm.track_num.value == "1z9r29a4")){
           alert('Please enter a tracking number!');
           theForm.track_num.style.backgroundColor='pink';
     
           theForm.track_num.focus();
           return false;
        }}  
    
    if(theForm.shipper){
      if (theForm.shipper.selectedIndex == 0)
      {
        alert("The first \"Shipper\" option is not a valid selection.  Please choose one of the other options.");
        theForm.shipper.style.backgroundColor='pink';
        theForm.shipper.focus();
        return (false);
      }}
    
     return (true);
    
    }
    
    
    function chkFormTrack(form) { 
    
    var isChecked=0; 
    
    for (i=0;i<form.elements.length;i++) { 
    var obj = form.elements[i]; 
    if (obj.type == 'checkbox') { 
    if (obj.checked == true) { isChecked++; } 
    } 
    if (isChecked > 0) { 
      return true;
     } 
    } 
    if (isChecked > 0) { return true;} 
    else { alert('Please choose item(s) to attach.');
    return false;
     } 
    } 
    
    </script>

  • #2
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    What I would like to do is combine the chkFormTrack(form) function within the validateTracking function. How can this be done?

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,855
    Thanks
    22
    Thanked 157 Times in 148 Posts
    Does this work?

    Code:
    onsubmit="if (!validateTracking(this) || !chkFormTrack(this)) return false;"
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪


  •  

    Posting Permissions

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