2

I have a button with a href that sends data, and before that I want to show a popup using Bootbox.js

HTML:

<a href="submit?result=something"> 
  <button class="alert btn btn-primary" type="button">Submit</button>
</a>

JS:

$('alert').click(function(){
    bootbox.alert("Submitted!", function() {
        console.log("Alert Callback");
    });
});

This just performs the href action so it does not display the popup using Bootbox.js. Is there a way to perform a function and perform the href right after you close this?

For reference: http://bootboxjs.com

maregor
  • 777
  • 9
  • 32

2 Answers2

1

I think you can remove the the hyperlink from the HTML markup, just keep the button and then do something like this:-

$('.alert').click(function(){
    bootbox.alert("Submitted!", function() {
        console.log("Alert Callback");
        window.location.href = '/submit?result=something';
    });
});
palaѕн
  • 72,112
  • 17
  • 116
  • 136
1

You can use return false;:

$('.alert').click(function(e){ // missed the . for the class selector
    bootbox.alert("Submitted!", function() {
        location.href = this.parentNode.href;
    });
    return false;
});

Another suggestion is to use data-* attribute on button itself instead of wrapping it within an anchor:

<button class="alert btn btn-primary" data-href="submit?result=something" type="button">Submit</button>

then you can use this:

$('.alert').click(function(e){ // missed the . for the class selector
    bootbox.alert("Submitted!", function() {
        location.href = this.dataset['href'];
    });
});
Jai
  • 74,255
  • 12
  • 74
  • 103