ZSMJ
ZSMJ

Reputation: 99

data-loading-text not working

I want have have a "Loading. . ." whenever I click on the "Submit" button. In this case, how come it did not display the "Loading. . ." thingy? bootstrap 2.3.2

<input type="submit" data-loading-text="Loading..." disabled="disabled" style="" id="save" class="btn btn-primary " value="Submit" name="save">

Here's my JS:

$('#save').click(function() {
    var btn = $(this);
    btn.button('loading');
    btn.button('reset');
});

I can't find any error in console either. What did I miss?

Upvotes: 10

Views: 7198

Answers (2)

Ahosan Karim Asik
Ahosan Karim Asik

Reputation: 3299

Try this:

$('#save').click(function() {
      var btn = $(this);
      btn.val(btn.data("loading-text")); setTimeout(function() {
          btn.val('reset');
        }, 2000);
      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="submit" data-loading-text="Loading..." style="" id="save" class="btn btn-primary " value="Submit" name="save">

Upvotes: 1

Radonirina Maminiaina
Radonirina Maminiaina

Reputation: 7004

Here's an example, you need to btn.val('loading...'); because you change the value of your input. Here's a working demo.

Upvotes: 0

Related Questions