views:

147

answers:

2

I currently have my code set to disable the submit button when the field is submitted. Is there a way I can make it re-enable the submit button later?

The first half of my code.

$("#segment").submit(function () {
$(':submit').attr('disabled', 'disbled');

The second half of my code.

if (data == 'success') {
            $("#segment").slideUp(function () {
                $("#segment").after('<div class="approvedMessage">YES</div>');
                setTimeout(function () {
                    $("#segment").slideDown();
                    $('.approvedMessage').fadeOut();
                },
                2000);
            });
        }

Whereas after 2 seconds it slides back down, I also want it to re-enable the form in the second half of the code, right before it slides back down to show the form again.

The form is submitted regardless if the data is false or true, etc. It does a slideUp, I just want the submit button to re-enable itself again before the message text slides down to show the form again.

A: 

$(':submit').attr('disabled', false); ?

gms8994
This won't work.
Philippe Leybaert
$(':submit').attr('disabled', ''); will work though.. Philippe Leybaert answer including removeAttr() is even better though.
Kenny Eliasson
+4  A: 

Simply remove the attribute:

$(":submit").removeAttr("disabled");

In your case:

if (data == 'success') {
        $("#segment").slideUp(function () {
            $("#segment").after('<div class="approvedMessage">YES</div>');
            setTimeout(function () {
                $(":submit").removeAttr("disabled");
                $("#segment").slideDown();
                $('.approvedMessage').fadeOut();
            },
            2000);
        });
    }
Philippe Leybaert
I understand it, thanks.
Homework
Still wonder why this got downvoted though...
Philippe Leybaert