Solved

Disable pressing on a submit button twice

Posted on 2001-07-05
16
370 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
[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
  • 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
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!

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

740 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