javascript - Confirm with modal bootstrap won't work -


i'm using bootstrap , want use modal launch button confirms user deletion action. example code bootstrap seems won't work me. looking examples forums , still won't work. 1 of example tried here. it's been 2 hours , still don't know whats wrong code. confirms button won't work whenever clicked confirm button, it's nothing. when moved mouse cursor on btn-ok, didn't see link overview in browser.

here code:

<button class="btn btn-default" data-href="delete.php?id=54" data-toggle="modal" data-target="#confirm">delete</button>  <div class="modal fade" id="confirm" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog">     <div class="modal-content">         <div class="modal-header">             ...         </div>         <div class="modal-body">             ...         </div>         <div class="modal-footer">             <button type="button" class="btn btn-default" data-dismiss="modal">cancel</button>             <a class="btn btn-danger btn-ok">delete</a>         </div>     </div> </div> 

try fiddle

https://jsfiddle.net/gildonei/pho9zp2f/9/

html code

<a class="btn btn-default btn-delete" href="delete.php?id=54">delete</a> <div class="modal fade" id="my-modal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true">     <div class="modal-dialog">         <div class="modal-content">             <div class="modal-header">...</div>             <div class="modal-body">...</div>             <div class="modal-footer">                 <a id="bt-modal-cancel" href="#" class="btn btn-default" data-dismiss="modal">cancel</a>                  <a id="bt-modal-confirm" class="btn btn-danger btn-ok">delete</a>              </div>         </div>     </div> </div> 

javascript code

$(function(){     var $mymodal = jquery('#my-modal');      // modal delete record     var $btdelete = jquery('.btn-delete');     if ($btdelete.length) {         $btdelete.click(function(e){             e.preventdefault();              var url = jquery(this).attr('href');             var id = url.replace(/[^0-9]/g, '');              // objects alert modal             var $dsbody = $mymodal.find('div.modal-body');             var $dstitle = $mymodal.find('div.modal-header h3');             var $btconfirm = jquery('#bt-modal-confirm');             var $btcancel = jquery('#bt-modal-cancel');              $dsbody.html('<p>are sure want delete record #' + id + '?</p>');             $dstitle.html('delete record');              $mymodal.modal({                 show: true             });               $btconfirm.attr('href', url).removeattr('data-dismiss');             $btcancel.click(function(){                 $dstitle.html('warning');                 $dsbody.html('<p>notice</p>');                 $btconfirm.attr('href', '#').attr('data-dismiss', 'modal');             });         });     }  }); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -