Solved

Disable pressing on a submit button twice

Posted on 2001-07-05
16
371 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

710 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