Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

Disable pressing on a submit button twice

I want to disable pressing on submit button after the form has been submited, so my command will not processed twice.
When i use my 'inLoad' variable, the second press lock the current page in browser and the next page not reached.

What can i do?
 
0
galor
Asked:
galor
  • 7
  • 2
  • 2
  • +4
1 Solution
 
daniel_cCommented:
Change your submit button into button, and execute javascript function to do that!
0
 
daniel_cCommented:
Here is a simple example:

<SCRIPT LANGUAGE=Javascript>
  function DoIt()
  {
     document.form1.buSubmit.disabled = true;
     document.form1.submit();
  }
</SCRIPT>
<FORM name=form1 Action="somepage.asp" method="post">
Name: <INPUT TYPE=text>
<BR>
<INPUT TYPE=button Name=buSubmit Value="Submit" OnClick="DoIt()">
</FORM>
0
 
daniel_cCommented:
Here is a simple example:

<SCRIPT LANGUAGE=Javascript>
  function DoIt()
  {
     document.form1.buSubmit.disabled = true;
     document.form1.submit();
  }
</SCRIPT>
<FORM name=form1 Action="somepage.asp" method="post">
Name: <INPUT TYPE=text>
<BR>
<INPUT TYPE=button Name=buSubmit Value="Submit" OnClick="DoIt()">
</FORM>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nimaigCommented:
<html>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--
     var isSubmitComplete = false;
     
     function submitForm(){
          if(!isSubmitComplete){
               isSubmitComplete = true;
               alert("Form submit");
          }else{
               alert("Form already submitted");
          }
     }

//End-->
</script>
</HEAD>
<body>
<form method="post" action="try.html" name="f1">
     <input type="text">
     <input type="button" onClick="submitForm()" value="submit">
</form>
</body>
</html>
0
 
nimaigCommented:
note: Button can't be disabled in Netscape
0
 
dfc106Commented:
You can use DHTML to remove the button:
<html>
<head>
<script language="JavaScript">

function submitForm() {
     removeMe.innerHTML='';

     document.frontDoor.submit();

}
</script>
</head>
<body >
<form name='frontDoor' action='submitme.html'>
<input type=text name='login_id'>
<br>
<input type=text name='login_password'>
<div id='removeMe'>
<input type=button onclick='submitForm()'>
</div>
</form>
</body>
</html>

0
 
hidayathCommented:
A simple suggestion , as soon as the user hits the submit btn just disable it
0
 
daniel_cCommented:
hidayath, please refer to EE ethics.
Leave your suggestion as a comment, and let galor select the best solution for him.
0
 
beg3aCommented:
does anyone else see the irony that danielc hit the submit button twice to post his answer.  EE should implement his code:)
0
 
daniel_cCommented:
What do you mean beg3a? I didn't mean to say that I gave the best solution, just try to obey EE ethics.
Please refer to: http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20110692

No hard feeling though!

^_^
0
 
beg3aCommented:
I was just pointing out the humor in the fact that when you posted your code about how to disable a person from submitting a form twice, you accidentally posted your code twice.  Get it?  haha.

As far as your code I think it should be chosen as the correct answer.
0
 
daniel_cCommented:
Hehehe, actually it was not because of submitting a form twice, but probably pressed refresh button twice!? ;-)
0
 
zvonkoCommented:
when we are talking about jokes...
how about this:
<html>
<title> checkAndSubmit() </title>
<head>
<SCRIPT LANGUAGE=JavaScript>
<!--
var submitted = false;
function checkAndSubmit() {
 if (!submitted) {
   document.myForm.mySubmit.value = "submitted...";
   return submitted = true;
 }
 document.myForm.mySubmit.value = "don't do this again.";
 return false;
}
// -->
</SCRIPT>
</head>
<body>
<FORM onSubmit="return checkAndSubmit()" METHOD=post name=myForm>
<input type=text name=Name>
<input type=submit name=mySubmit>
</form>
</body>
</html>

(perhaps jokes also earn points ;-))
Regards,
zvonko
0
 
zvonkoCommented:
upps...
when testing the joke on IE give it an action; like this:
<FORM onSubmit="return checkAndSubmit()" METHOD=post name=myForm action="http://localhost/test">

Otherwise it is to fast reloaded and you see no effects...
0
 
galorAuthor Commented:
I forgot to write that i use <A> tag and not button, so i can not use the 'disabled' property.
I use the removeMe.innerHTML="" answer.
0
 
daniel_cCommented:
Galor, you have given grade to the wrong person then!
It should be for dfc_106!

:)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now