Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable submit button untill any form element change?

Tags:

jquery

Heres what im trying to do. After the form is submitted, i want to disable the submit button until any form element is changed. I already got it almost working using a different question on stackoverflow:

$('#myform').find (':submit').attr ('disabled', 'disabled');

// Re-enable submit
var form = $('#myform');
$(':input', form.get(0)).live ('change', function (e) {
    form.find (':submit').removeAttr ('disabled');
});

One problem is that the if the button is disabled, and the user clicks the button, that counds as a change and its now enabled. So a simple double click of the button re-submits! Any suggestions?

like image 950
Jonah Katz Avatar asked Mar 10 '26 16:03

Jonah Katz


1 Answers

[type!="submit"]

http://api.jquery.com/attribute-not-equal-selector/

$(':input[type!="submit"]', form.get(0)).live ('change', function (e) {
    form.find (':submit').removeAttr ('disabled');
});
like image 139
genesis Avatar answered Mar 12 '26 11:03

genesis