button attribute disabled true jquery

by Prakash 2013-07-19 12:59:35

While submitting a form in ajax may want the submit button to be disabled because the user may click the button repeatedly.

The following code disables the submit button when clicked and enables it again after the response is received.


<form action="ajaxpage.php" method="get" id="prev_next_other_form" >
<input type="hidden" name="otherstart" value="<?=$otherstart?>" />
<input type="hidden" name="otherlimit" value="<?=$otherlimit?>" />
<input class="but" type="submit" value="next" />
</form>

<script type="text/javascript">
$(document).ready(function(){
$(".prev_next_other_form").submit(function(){
$(".but").disabled("disabled",true);
$.ajax({
url:form.action,
type:form.method,
data:$(form).serialize(),
success:function(response){
//success process
},
error: function(jqXHR, textStatus, errorThrown){
//error process
}
});
$(".but").disabled("false",true);
});
});
</script>

Tagged in:

786
like
0
dislike
0
mail
flag

You must LOGIN to add comments