?
Solved

onSubmit="return checkForm(this) && submitonce(this)"

Posted on 2003-03-06
10
Medium Priority
?
1,425 Views
Last Modified: 2008-02-01
checkForm works fine when on onSubmit alone, submitonce works fine when on onSubmit alone.  When I insert...

onSubmit="return checkForm(this) && submitonce(this)"

checkForm works, submitonce does not.

I have a heavily hit site with form submission and have backend perl script that dumps doubles but seems since I am on shared environment some doubles get through do to those fine "double clickers".  Bottomline, need to prevent the double or multiple clicker.  submitonce deactivates the submit button, works fine when alone in onSubmit.

Thanks in advance...Gary

0
Comment
Question by:precision
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
10 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 8080547
>>>onSubmit="return checkForm(this) && submitonce(this)"

try this
assuming that checkForm() is one function and submitonce() is another function
onSubmit="return checkForm(this);submitonce(this)"

0
 
LVL 5

Expert Comment

by:gator4life
ID: 8080569
precision -

Change the onSubmit to:

     onSubmit="return checkForm(this);"

Then, put submitonce() into checkForm() as the first line:

     function checkForm(oForm) {

          submitonce(oForm);

          // REST OF checkForm
     }

Notice that if checkForm returns false, you will need to reenable the submit button before returning the false back to the onSubmit, so that the button can be used again if something was not validated.

gator4life
(chomp, chomp)
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 8080604
How about braces?

onSubmit="return (checkForm(this) && submitonce(this))"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:precision
ID: 8082142
Tried all above, still nothing.  Went from:

onSubmit="return checkForm(this) && submitonce(this)"
to:
onSubmit="return checkForm(this)"

Below was inserted into checkForm() right at end.  checkForm works like a charm, below does nothing for disabling submit button after all passes checkForm.

??????


if (document.all||document.getElementById){
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=true
}
}

</script>
0
 
LVL 16

Accepted Solution

by:
jaysolomon earned 136 total points
ID: 8082201
use this to disable the button

<SCRIPT language='javascript'>
function disableButton(theButton)
{
  theButton.value="Processing...";
  theButton.disabled = true;
  theButton.form.submit();
}
</script>

<INPUT TYPE="SUBMIT" VALUE="Submit" name="mySubmit" onclick="disableButton(this);">
0
 

Author Comment

by:precision
ID: 8087396
Here is my actual script, I shortened the checkForm for this posting...I just don't get why it will not work...thanks...Gary

<FORM onSubmit="return checkForm(this)"

****************************************

<script language="JavaScript">
    function checkForm(form) {

foundError = false;
// CHECK FOR BLANK FIELDS
inputVal=form.fname.value
if(inputVal == "") {
            alert("You left FIRST NAME field blank!");
            form.fname.focus();
            return false;
}
inputVal=form.lname.value
if(inputVal == "") {
            alert("You left LAST NAME field blank!");
            form.lname.focus();
            return false;
}
if (form.state.options != null) {
     if(foundError == false && form.state.options[form.state.selectedIndex].value == "Pick One") {
               foundError = true;
                 alert("You left the State field blank!");
                 form.state.focus();
                 return false;
     }
}

// CHECK FOR VALID EMAIL ADDRESS
inputVal=form.email.value
if(inputVal == "") {
            alert("You left the EMAIL field blank!");
            form.email.focus();
            return false;
}

inputVal=form.email.value
                if(inputVal.indexOf('\@', 0) == "-1"){
            alert("Your Email Address must contain an \@ !");
            form.email.focus();
                        return false;
     }
// CHECK FOR EMAIL MATCH
if(form.email.value != form.remail.value) {
                foundError = true;
            alert("Your email addresses did not match!");
            form.email.focus();
            return false;
}

//DISABLE SUBMIT BUTTON
if (document.all||document.getElementById){
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
tempobj.disabled=true

}

</script>
0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 132 total points
ID: 8091790
How about this one:

<html>
<head>
<script language="JavaScript">
   function checkForm(theForm) {

foundError = false;
// CHECK FOR BLANK FIELDS
inputVal=theForm.fname.value
if(inputVal == "") {
           alert("You left FIRST NAME field blank!");
           theForm.fname.focus();
           return false;
}
inputVal=theForm.lname.value
if(inputVal == "") {
           alert("You left LAST NAME field blank!");
           theForm.lname.focus();
           return false;
}
if (theForm.state.options != null) {
    if(foundError == false && theForm.state.options[theForm.state.selectedIndex].value == "Pick One") {
              foundError = true;
                alert("You left the State field blank!");
                theForm.state.focus();
                return false;
    }
}

// CHECK FOR VALID EMAIL ADDRESS
inputVal=theForm.email.value
if(inputVal == "") {
           alert("You left the EMAIL field blank!");
           theForm.email.focus();
           return false;
}

inputVal=theForm.email.value
               if(inputVal.indexOf('\@', 0) == "-1"){
           alert("Your Email Address must contain an \@ !");
           theForm.email.focus();
                       return false;
    }
// CHECK FOR EMAIL MATCH
if(theForm.email.value != theForm.remail.value) {
               foundError = true;
           alert("Your email addresses did not match!");
           theForm.email.focus();
           return false;
}

//DISABLE SUBMIT BUTTON
 if (theForm.Submit.value=="Submit"){
      theForm.Submit.disabled=true;
      theForm.Submit.value="Submitted...";
      theForm.Reset.disabled=true;
      return true;
 } else return false;

}
</script>
</head>
<body>
<FORM onSubmit="return checkForm(this)">
<input type=text name=fname><br>
<input type=text name=lname><br>
<select name=state>
<option value="Pick One">Pick One
<option>NY
</select>
<input type=text name=email><br>
<input type=text name=remail><br>
<input type=submit value=Submit name=Submit>
<input type=reset value=Reset name=Reset>
</form>
</body>
</html>


0
 
LVL 5

Assisted Solution

by:gator4life
gator4life earned 132 total points
ID: 8099032
precision -

Try this solution.  It is a bit more robust, has a much better way of checking for valid email addresses, and is broken down into smaller components:

<html>

<head>
     <script type="text/javascript">
     <!--
          function DisableButtons(oForm, bDisable) {
         
               for (var i = 0; i < oForm.length; i++) {
               
                    var oTemp = oForm.elements[i];
                    if ((oTemp.type.toLowerCase() == 'submit') || (oTemp.type.toLowerCase() == 'reset')) oTemp.disabled = bDisable;
               }
          }
     
          function CheckStandardField(oField, sAlertMsg) {
         
               if (oField.value.replace(/\s/g, '') == '') {
               
                    window.alert(sAlertMsg);
                    oField.focus();
                    return false;
               }
               else
                    return true;
          }
     
          function CheckForm(oForm) {

               DisableButtons(oForm, true);

               var bFoundError = false;

               if (!CheckStandardField(oForm.fname, 'You left the FIRST NAME field blank!')) return false;
               if (!CheckStandardField(oForm.lname, 'You left the LAST NAME field blank!')) return false;

               with (oForm.state) {
               
                    if (options != null) {

                         if ((bFoundError == false) && (options[selectedIndex].value == 'Pick One')) {

                              bFoundError = true;
                              window.alert('You left the STATE field blank!');
                              focus();
                              return false;
                         }
                    }
               }
               
               if (!CheckStandardField(oForm.email, 'You left the EMAIL ADDRESS field blank!')) return false;

               with (oForm.email) {
               
                    var xEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
               
                    if (!xEmail.test(value)) {
         
                         window.alert('Your EMAIL ADDRESS is not valid!');
                         focus();
                         return false;
                    }
         
                    if (value != oForm.remail.value) {
         
                         foundError = true;
                         window.alert('Your EMAIL ADDRESSES did not match!');
                         focus();
                         return false;
                    }
               }
          }
         
          function Validate(oForm) {
         
               if (!CheckForm(oForm)) {
               
                    DisableButtons(oForm, false);
                    return false;
               }
               else
                    return true;
          }
     //-->
     </script>
</head>

<body>
     <form name="myForm" onsubmit="return Validate(this);">
          FIRST NAME:
          <input type="text" name="fname" size="20"><br>
          LAST NAME:
          <input type="text" name="lname" size="20"><br>
          STATE:
          <select name="state" size="1">
               <option value="Pick One">Pick One</option>
               <option value="FL">Florida</option>
          </select><br>
          EMAIL ADDRESS:
          <input type="text" name="email" size="20"><br>
          REENTER EMAIL ADDRESS:
          <input type="text" name="remail" size="20"><br>
          <br>
          <input type="submit" value="SUBMIT">
          <input type="reset" value="RESET">
     </form>
</body>

</html>

Good luck!

gator4life
(chomp, chomp)
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10097817
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: jaysolomon {http:#8082201} & Zvonko {http:#8091790} & gator4life {http:#8099032}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question