Solved

disable the submit button when clicked

Posted on 2003-11-07
10
1,481 Views
Last Modified: 2008-03-17
Hi all,
  I have a form where I want the submit button to be disabled when the user has click on it. This is because the process is quite long and I want to avoid the impatient users from clicking on it again...

In my form I have some javascript validations exemple
<form blabla on submit validation form...>
When the submit button is click, the form is being validated if all good then the process begins. But before returning to the next page it's quite long like I said.. so can I do something like

<input type="submit" name="go" value="save" onclick="javascript:<disable my button at this point"> ?

Thanks for the answer

0
Comment
Question by:DaDMan
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 4

Expert Comment

by:intrwrks
ID: 9703841
Try this out:

<input type="submit" name="go" value="save" onclick="javascript:this.setAttribute('disabled','true');">
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9703849
<input type="submit" name="go" value="save" onclick="this.disabled=true;">

be sure to re-enable the button if your javascript validations finds an error

0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9703861
and the re-enable would be

function validation(){
...... all your validation crap .....

.......... whoa somethings wrong .........
 alert('You idiot you filled out the form wrong. Do it again');
 document.yourFormName.go.disabled=false;


}

0
 
LVL 1

Author Comment

by:DaDMan
ID: 9703986
Hey guys your on the spot. This is what I want but I have a problem now... the button is disable but does not submit anything.. just stand there.. disabled!! :-)

Any ideas?
0
 
LVL 1

Author Comment

by:DaDMan
ID: 9703998
and this is for both method you've offered...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 10

Accepted Solution

by:
Bustarooms earned 50 total points
ID: 9704000
in that case i would move it

<form name="yourform" onsubmit="this.go.disabled=true;return validation();">
0
 
LVL 25

Expert Comment

by:devic
ID: 9704035
try this:
============
<input type="submit" name="go" value="save" onclick="this.disabled=true;this.form.submit();">
0
 
LVL 1

Author Comment

by:DaDMan
ID: 9704047
yeah man!! right on.

Thanks alot

0
 

Expert Comment

by:kahkaha
ID: 14855924
but there is a specific problem with the code
<input type="submit" name="go" value="save" onclick="this.disabled=true;this.form.submit();">

this arises when you control the variable go, for example with PHP. Its value comes null or zero. thats why if you check the form's submittal by checking the button's value, PHP does not understand naturally that the form is submitted. if the button is disabled when submitting, its value transmits as zero or null
0
 
LVL 25

Expert Comment

by:devic
ID: 14855989
hi kahkaha,

then maybe this one:
=================
<form action=http://www.sembel.net/tools/q.php>
      <input type=text name=kuku value=hurra>
      <input type="submit" name="go" value="save" onclick="this.onclick=function(){return false};this.form.submit();">
</form>


btw, you need open a new question.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

706 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

21 Experts available now in Live!

Get 1:1 Help Now