Solved

disable the submit button when clicked

Posted on 2003-11-07
10
1,486 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
chrome and edge version of getElementById("p").attributes("title").value 2 36
Else condition 9 23
html Uncheck Checkbox 2 25
How do I show metrics with PHP or Javascript 6 32
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

856 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