I've checked similar questions here, but none of them seemed to solve my problem.
I'm trying to add data-loading-text to my submit button, but with no luck so far.
I'm using Bootstrap 4!
Here is my HTML:
<button type="submit" id="submit" class="btn btn-primary btn-lg mt-2" data-loading-text="Sending...">Submit message!</button>
This was the last jquery code I tried:
$(function() {
$(".btn").click(function(){
$(this).submit('loading').delay(1000).queue(function() {
// $(this).button('reset');
});
});
});
Thanks
I've checked similar questions here, but none of them seemed to solve my problem.
I'm trying to add data-loading-text to my submit button, but with no luck so far.
I'm using Bootstrap 4!
Here is my HTML:
<button type="submit" id="submit" class="btn btn-primary btn-lg mt-2" data-loading-text="Sending...">Submit message!</button>
This was the last jquery code I tried:
$(function() {
$(".btn").click(function(){
$(this).submit('loading').delay(1000).queue(function() {
// $(this).button('reset');
});
});
});
Thanks
Try this.
<!DOCTYPE html>
<html>
<head>
<style></style>
<script src="https://ajax.googleapis./ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>
function MyCustomFunction(){
$("#submit").text("Loading...");
$(this).submit('loading').delay(1000).queue(function () {
// $(this).button('reset');
});
}
</script>
</head>
<body>
<button type="submit" onclick="MyCustomFunction()" id="submit" class="btn btn-primary btn-lg mt-2" data-loading-text="Sending...">Submit message!</button>
</body>
</html>
In case of Submit button the only possible way is to bind a custom function on click and change the action attribute to event handler.
I think this is the most easy way to get the result you need:
HTML:
<button type="submit" class="btn btn-primary btn-lg btn-block" data-loading-text="Your order is being processed...">Order now</button>
JAVASCRIPT / JQUERY:
$(".btn").on('click', function () {
var dataLoadingText = $(this).attr("data-loading-text");
if (typeof dataLoadingText !== typeof undefined && dataLoadingText !== false) {
console.log(dataLoadingText);
$(this).text(dataLoadingText).addClass("disabled");
}
});