javascript - Allow Button Submit on Click with jQuery -
i have web page has submit button. submit button looks following:
<button type="submit" class="btn btn-primary wait-on-click"> <span>submit</span> </button>
when user clicks submit button, want disable button , let user know happening. that, have following javascript:
$('.wait-on-click').click(function(e) { e.preventdefault(); $(this).prop('disabled', true); $('span', this).text('please wait...'); });
the button disables. text updated. however, submit not submitted server. if comment out body of javascript function, works fine. not understand how fix this.
thank you!
i believe problem line
e.preventdefault();
this preventing default behavior of submit button, i.e., submitting! therefore, remove it.
update
after testing, have found problem. believe problem line
$(this).prop('disabled', true);
for reason, preventing form submitting. therefore, put in submit handler.
$('.wait-on-click').click(function(e) { $('span', this).text('please wait...'); }); $('form').on('submit', function() { $('.wait-on-click').prop('disabled', true); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <form> <input name="n" /> <button type="submit" class="btn btn-primary wait-on-click"> <span>submit</span> </button> </form>
Comments
Post a Comment