javascript - How to trigger bootstrap modal if a condition statement is met - Stack Overflow

Honestly I have dig deep here and seen something similar to what am looking for, but none of them seems

Honestly I have dig deep here and seen something similar to what am looking for, but none of them seems to work for me. I know am missing it somewhere, somehow.

My challenge is that I have a button link on clicking performs a validation check and if the no error is found, i want to trigger a modal window.

below are my code sample

Preview

onclicking the button the javascript function runs very well, but i have not been able to get the modal to load when error < 1. Please help

<script>
function validate_radiobutton_group(form){
  var error = 0;
  if(error>0){
    alert("........");
    return false;
  }
  else{
    $('#myModal').modal({
    show: true
  });
}
}

</script>



<div aria-hidden="false" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" class="modal fade" id="myModal" style="width: 640px;">
  <div class="modal-header">
    <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
    <h3 id="myModalLabel"></h3>
  </div>
  <div class="modal-body">
</div>
  <div class="modal-footer">
    <button data-dismiss="modal" class="btn btn-primary">Close</button>
  </div>
</div><!--#myModal-->

Honestly I have dig deep here and seen something similar to what am looking for, but none of them seems to work for me. I know am missing it somewhere, somehow.

My challenge is that I have a button link on clicking performs a validation check and if the no error is found, i want to trigger a modal window.

below are my code sample

Preview

onclicking the button the javascript function runs very well, but i have not been able to get the modal to load when error < 1. Please help

<script>
function validate_radiobutton_group(form){
  var error = 0;
  if(error>0){
    alert("........");
    return false;
  }
  else{
    $('#myModal').modal({
    show: true
  });
}
}

</script>



<div aria-hidden="false" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" class="modal fade" id="myModal" style="width: 640px;">
  <div class="modal-header">
    <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
    <h3 id="myModalLabel"></h3>
  </div>
  <div class="modal-body">
</div>
  <div class="modal-footer">
    <button data-dismiss="modal" class="btn btn-primary">Close</button>
  </div>
</div><!--#myModal-->
Share Improve this question edited Mar 23, 2014 at 20:44 lando 4402 silver badges13 bronze badges asked Mar 23, 2014 at 17:35 GiftoGifto 211 gold badge2 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

According to the documentation, to show the modal you call:

$('#myModal').modal('show');

instead of:

$('#myModal').modal({
   show: true
});

Check the markup for your modal

I created a plunker with modal markup from bootstraps docs and it works as expected. http://plnkr.co/edit/vyCL7WqQ014X6wJ8AUjw?p=preview

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745399279a4626025.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信