12

I want to disable submit button in my form once it s clicked to restrict user to click it again and again i tried this with jquery

$('form').submit(function()
{  
    var formId = this.id;
    if (formId != ''){
        $('#'+formId+' :input[type=submit]').attr('disabled',true);
        this.submit();
    }
}); 

my problem s that i have two submit button s in my page which i m checking in controller to direct but i m not getting any post values once i disable the submit button in my form. Is there any other way to prevent user to restrict multiple clicks ?

1

4 Answers 4

22

Have an id or a name for the submit button. Disable that button only

For example:

HTML

<form id="frm_name">
     <input type="submit" id="btn_submit" value="Submit" />
</form>

jQuery

...
if (formId != ''){
    $('#btn_submit').attr('disabled',true);
    this.submit();
}
...
Sign up to request clarification or add additional context in comments.

1 Comment

s this will solve my problem as this s the commonfunction which i want to call all over my app i can call this function in onsubmit of each button with formid and disable field parmeter
3

In my case $('#btn_submit').prop("disabled", true); worked!

Update:

I was using kendo grid inside some specific rows I want to disable Edit and Delete inline buttons. I tried many alternate ways to disable it but .prop() worked like charm!

1 Comment

This is in the low quality posts queue. I'm voting it looks okay, but you should add some more information about why this works when the OP's attempts didn't.
2

You can also disable the event like this,

$('form').submit(function(e)
{ 

e.preventDefault();
//then carry out another way of submitting the content.

}

Comments

0

$('#submit_button_1').prop('disabled', true);
$('#submit_button_2').prop('disabled', true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="button" id="submit_button_1" value="Submit" />
<button type="submit" id="submit_button_2">Submit</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.