Jonah Katz
Jonah Katz

Reputation: 5288

Disable submit button untill any form element change?

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?

Upvotes: 3

Views: 1606

Answers (1)

genesis
genesis

Reputation: 50976

[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');
});

Upvotes: 3

Related Questions