Skip to content Skip to sidebar Skip to footer

Javascript : Button Text Reverts Back To Default When The Page Is Reloaded

I have a button that i want to change it's text when i click on it from disable to enable , the button text is already changed but a prompt dialogue box opens when i click the disa

Solution 1:

If you already use jQuery, use it to also bing the 'click' event, and to retrieve the relevant data (using data-attributes) like so:

$('.myBtn').on('click', function(){
  var $btn = $(this)
  $("#userId_delete").val($btn.data('user-id'));
  $("#userName_delete").text($btn.data('user-name'));
  var newVal = $btn.val() == 'Disable' ? 'Enable' : 'Disable';
  $btn.val(newVal);
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputclass="myBtn"type="button"data-user-id="5"data-user-name="userNameHere"value="Disable"/>

Post a Comment for "Javascript : Button Text Reverts Back To Default When The Page Is Reloaded"