Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable button after one click with validation using javascript? [duplicate]

Tags:

javascript

First I want to validate some of the field values entered or not. After that When i click the submit button, the button must be disabled after one click to avoid duplicate submission. How to do that using javascript?

<script type="text/javascript" language="javascript">
    function ValidateIt() {
      if (document.getElementById('ddlProblemCategory').value == 0) {
           alert("Please fill some value");
           return false;
      }
           return true;
    }
    function DisableIt() {
        if (ValidateIt() == true)
          document.getElementById('btnSaveProblem').disabled = true;
    }  
</script>

like image 264
RGS Avatar asked Jun 14 '13 18:06

RGS


2 Answers

Call function submitbtn onclick of the button.

Use

function submitbtn(){
getElementById("Submit_id").disabled=true;
//Validation code goes here
}
like image 86
TechBytes Avatar answered Oct 07 '22 03:10

TechBytes


You can add an onclick handler to your button:

document.getElementById("idOfButton").onclick = function() {
    //disable
    this.disabled = true;

    //do some validation stuff
}
like image 40
tymeJV Avatar answered Oct 07 '22 03:10

tymeJV