Rahul.Valani Rahul.Valani - 2 months ago 12
HTML Question

Convert alert message into pop-up

I am able to create a alert message when user click a particular set of product but How do I display pop-up instead of alert message
Code:

<script>
$(document).ready(function(){
$('.pre-sale-product').on('click', function(){
$('.productcart').addClass('pre-sale-item-included');
});
$('.productcart').on('click', function(){
if($(this).hasClass('pre-sale-item-included')){
alert('will ship on <?php echo $new_date?>. Do you agree?');
}
});
})
</script>
<!-- Modal -->
<div class="modal fade" id="myModal_product" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

</div>
</div>


I want this pop-up instead of alert with option saying tick yes as a check box and it moves further

Answer

You just need to use the $('#myModal_product').modal('show');

Try this:

$(document).ready(function() {
  $('.pre-sale-product').on('click', function() {
    $('.productcart').addClass('pre-sale-item-included');
  });
  $('.productcart').on('click', function() {
    if ($(this).hasClass('pre-sale-item-included')) {
      $('#myModal_product').modal('show');
    }
  });
})
.pre-sale-item-included {
  border-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Modal -->
<div class="modal fade" id="myModal_product" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Will ship on <?php echo $new_date?>. Do you agree?</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success btn-default" data-dismiss="modal">Yes</button>
        <button type="button" class="btn btn-danger btn-default" data-dismiss="modal">No</button>
      </div>
    </div>
  </div>
</div>

<input type="button" class="pre-sale-product" value="pre-sale-product" />
<input type="button" class="productcart" value="productcart" />