blay
blay

Reputation: 225

Button Change on data submit to server

i use the script below to disable button when a user submits data to the server. it works fine with firefox but doesn't work with chrome. when you submit on chrome the button changes to data sent but when you check the database you wouldn't find it there, but on firefox it works perfectly, when the button changes to data sent, you check on the database and you find it there

<script language="javascript">
$(function(){
  $(".btn-style1").click(function(){
        $(this).val('data sent');
        $(this).attr('disabled', 'disabled');
  });
});
</script>

Upvotes: 0

Views: 128

Answers (1)

Bharat Ranpariya
Bharat Ranpariya

Reputation: 1253

Put attribute value as true / false instead of disabled. it will work on all browser. check below code. here i change attribute value as true instead of disabled. check it by executing below snippet. I also added form , so that you can check form submit by clicking button.

$(function(){
 $(".btn-style1").click(function(){
    $(this).val('data sent');
    $(this).attr('disabled', true);
   return true;
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<form action="http://stackoverflow.com/posts/xxx/edit">
 
<input type="hidden" name="a" value="abc"/>
<button type="submit" class='btn-style1' >Click</button>
</form>

Upvotes: 2

Related Questions