Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top