-1

I have a problem with this line of code :

<script type='text/javascript'>
function delete_user( id ){

    var answer = confirm('Are you sure?');

    //if user clicked ok
    if ( answer ){
        //redirect to url with action as delete and id to the record to be deleted
        window.location = 'delete.php?id=' + id;
    }
}
</script>

How to apply the bootbox.js here. i hate the old javascript dialog box. how can i change this?

i already did this line :

<script src="bootstrap.min.js"></script>

still not working.

Scape Goat
  • 45
  • 2
  • 7
  • Why not just modify/improve your [original question](http://stackoverflow.com/questions/25468389/changing-javascript-confirm-dialog-box-to-bootstrap)? – Marc Baumbach Aug 24 '14 at 07:03

3 Answers3

1

Just do this :

Suppose you have button for delete

<button class="delete-it">Delete</delete>

Write the this under click event of class delete-it

 $(".delete-it").click(function(){
    bootbox.confirm("Are you sure?", function(result) {
      if(result)
          window.location = 'delete.php?id=' + id;
    }); 
  });

As per comments below :

Using onclick is considered as bad practice. If you have $id value wrap it on data-attribute like this

<a href='#' data-id=' {$id }' class='delete-it'>Delete</a>

And change JS in to this :

 $(".delete-it").click(function(){
    var id = $(this).data('id');
    bootbox.confirm("Are you sure?", function(result) {
      if(result)
          window.location = 'delete.php?id=' + id;
    }); 
  });
Rahul Patil
  • 5,656
  • 6
  • 37
  • 65
0

You can display the confirm dialog box in bootbox as follows

bootbox.confirm("Are you sure you want to Delete?", function(result) {
  if(result)
      window.location = 'delete.php?id=' + id;
});

You will get the result either as True or False depending on clicking on Yes or No in the Dialog Box.

For further information on bootbox confirm dialog box, you can look into here

Earth
  • 3,477
  • 6
  • 37
  • 78
-1

Try this:

<!-- JS dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="bootstrap.min.js"></script>

<!-- bootbox code -->
<script src="bootbox.min.js"></script>

<script type='text/javascript'>

function delete_user( id )
{
    bootbox.confirm("Are you sure?", function(result) 
    {
        answer = result;
    }); 

    //if user clicked ok
    if ( answer ){
        //redirect to url with action as delete and id to the record to be deleted
        window.location = 'delete.php?id=' + id;
    }
}
</script>
S.Pols
  • 3,414
  • 2
  • 21
  • 42