Search code examples
javascripttwitter-bootstrapalertconfirm

bootstrap confirm box alert not working


<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">
    src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
  </script>
</head>

<script>
function confirm() {
BootstrapDialog.confirm('Are you sure you want to do this?');}
</script>

<input type="button" value="confirm" onclick="confirm()" />

Hi. I'm trying to make a bootstrap confirm alert which is activated by a button input. I'm a total beginner, so it's probably something fundamental/obvious that I'm missing... Any help very much appreciated. Mike.


Solution

  • a few things:

    • your script tag is incorrect, need to be fixed
    • you most likely need the bootstrap.css
    • you need to add bootstrap-dialog.js

     function confirm() {
       BootstrapDialog.confirm('Are you sure you want to do this?');
     }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.35.1/js/bootstrap-dialog.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
    
    <input type="button" value="confirm" onclick="confirm()" />