0

I have a form like so:

<form action="" method="post" id="form" name="form" enctype="multipart/form-data">
<input name="action" type="submit" value="Send" />
</form>

I am using the latest version of the Jquery UI Button plugin. The value of the submit button MUST be submitted. Is there an easy way to disable the submit button after the form has been submitted, without using additional plugins such as "Lock Submit" - http://plugins.jquery.com/project/LockSubmit ?

Many thanks.

2
  • 1
    I think the form won't post the value of the submit button when it is disabled. Is this the problem? Commented Jul 9, 2011 at 14:00
  • Yeah - I think the only way of doing it reliably is using Lock Submit but I just wondered if the Jquery UI library catered for this instead. Commented Jul 9, 2011 at 14:08

4 Answers 4

3

When you set the disabled property of an element, it won't be submitted. The workaround is to set the disabled property after the form is submitted. You can use the setTimeout() function with a very short delay:

$("#form").submit(function() {
    setTimeout(function() {
        // .prop() requires jQuery 1.6 or higher
        $("#form :submit").prop("disabled", true);
    }, 100);
});

Demo here

Another trick, is to use a trick :) You can wrap the original submit button inside a div and hide it when the form submits.

Demo here

Sign up to request clarification or add additional context in comments.

1 Comment

I decided to go with the "trick" option as it is basically doing the same thing as "Lock Submit" without the hassle of using their library.
3

Easy just add type="button" to button attributes like

<button type="button" >not submit</button>

Comments

0

you mean

$('#form').submit(function() {$(this).find('input:[type="submit"]').button({disabled:true})});

?

Comments

0
$('#form').submit(function() {
  $(this).find('input[type="submit"]').disable();
});

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.