Solved

Disable pressing on a submit button twice

Posted on 2001-07-05
16
367 Views
Last Modified: 2008-02-01
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
Comment
Question by:galor
  • 7
  • 2
  • 2
  • +4
16 Comments
 
LVL 7

Expert Comment

by:daniel_c
ID: 6255796
Change your submit button into button, and execute javascript function to do that!
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6255806
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6255817
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
 
LVL 9

Expert Comment

by:nimaig
ID: 6255822
<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
 
LVL 9

Expert Comment

by:nimaig
ID: 6255830
note: Button can't be disabled in Netscape
0
 

Expert Comment

by:dfc106
ID: 6255833
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
 

Accepted Solution

by:
hidayath earned 200 total points
ID: 6257201
A simple suggestion , as soon as the user hits the submit btn just disable it
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6257312
hidayath, please refer to EE ethics.
Leave your suggestion as a comment, and let galor select the best solution for him.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Expert Comment

by:beg3a
ID: 6258658
does anyone else see the irony that danielc hit the submit button twice to post his answer.  EE should implement his code:)
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6259684
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
 
LVL 1

Expert Comment

by:beg3a
ID: 6260304
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6260858
Hehehe, actually it was not because of submitting a form twice, but probably pressed refresh button twice!? ;-)
0
 
LVL 10

Expert Comment

by:zvonko
ID: 6261660
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
 
LVL 10

Expert Comment

by:zvonko
ID: 6261675
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
 

Author Comment

by:galor
ID: 6262092
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6262137
Galor, you have given grade to the wrong person then!
It should be for dfc_106!

:)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now