• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1239
  • Last Modified:

Deactivate submit button with JavaScript/CSS

We've a submit button, styled by CSS:

                  <td><input name="submit" type="submit" value="Submit" class="form-button" /></td>      

How to deactivate/shade the button just after pressing submit (to avoid double click and visualize the deactivation).
0
go4java
Asked:
go4java
  • 2
  • 2
2 Solutions
 
JezcentralCommented:
<script language="javascript">
function disableField() {
    document.formXXX.elementXXX.disabled=true;
}
 
</script>
<td><input onclick="javascript:disableField();"> name="submit" type="submit" value="Submit" class="form-button" /></td>

Why do you want to disable it?

0
 
go4javaAuthor Commented:
...actually I need to disable the SUBMIT button first and afterwards it should evaluate form's action. Reason as above.
0
 
JezcentralCommented:
Just put: document.formXXX.elementXXX.disabled=true; in the first line of the form validation, then. (Just remember to set disabled to false, if validation fails and they need to resubmit.) Is this what you are after?
0
 
go4javaAuthor Commented:
I made it like that:

<script type="text/javascript">
// client side validation
function chkFormular() {
      // disable submit button
      document.getElementById('submButton').disabled=true;
      // error counter
      var i = 0;
      
      // ... place here validation code
      // ...
      // ...
      
      if (i>0) {            
            // enable submit button
            document.getElementById('submButton').disabled=false;
            return false;
      } else {                        
            return true;
      }
}
</script>

Reward follows...
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now