views:

584

answers:

4

Greetings

I am using the jquery disable on submit plug-in but I have a problem. If I disable the submit buttons they dont get passed back to the server so I cant tell which button was pressed. Is this normal? Is there anything I can do about it?

I really dont want to retool my website so I have to set a variable on form submission to tell which button was pressed.

Any ideas ?

A: 

You could do the submit via jquery and disable the button afterwards:

<input type="submit" value="do it!" onclick="$('#mainform').submit(); $(this).attr('disabled','disabled' ); $('#pleasewait').show();" />

EDIT: I forgot form.submit() is not asynchronous. You can do an ajax request instead:

$.ajax({
url: "someurl",
type:"POST",
cache: false,
dataType: "json",
success:gotIt,
async:true,
timeout:240000,
error:ajaxError,
data:$("#mainform").serialize()
});

or you could just .hide() the button, or after clicking it setting a non-functional onClick() handler and styling it to look disabled.

heeen
Don't i have to supply the post parameters do this ajax call too?
Jordie
+2  A: 

How to Disable the Submit Button of a Web Form

This method hides the button instead of disabling it, and programmatically inserts a disabled <button> tag to make it appear just like the submit button was disabled. Works great.

Josh Stodola
A: 

Here's a workaround I just found in a jQuery forum:

<script type="text/javascript">
    $(document).ready(function() {
        $("#sendSearch").click(function() {
            $('#loadingDiv').show();
            $('#sendSearch').attr("disabled", "disabled");

            // these two lines are the workaround
            this.form.submit();
            return true;
        });
    });
</script>
Thomas Eyde
doesn't work .
borisCallens
Yes it does, otherwise I wouldn't post it. In which browser does it not work? Version?
Thomas Eyde
+1 not sure why that got voted down but imho thats the best as it works with or without javascript
Jordie
Have you tried this with an ASP.NET web form? Didn't think so.
Josh Stodola
shouldn't it be return false at the end? / so it doesn't goes on to submit through that code path as well.
eglasius
A: 

Be more simple :)

var formid="#id-form-if-exists"; //Put here the id if exists
$("form"+formid).submit(function(){$("form"+formid+" input").attr("disabled",false);});

YEAH

CuSS