How to load Bootstrap model automatically when page loads?
I tried adding the following to my index file:
<script type="text/javascript"> $(window).load(function () { $('#myModal').modal('show'); }); </script> But its not working.
Try this, it should work :
<script type="text/javascript"> $(document).ready(function () { $('#myModal').modal('show'); }); </script> Building on Black Ops' answer, I noticed this might be addressing an older version of Bootstrap. In the newer version, the first time you click on the button, it initializes the modal. This needs to happen before it can be displayed. So, instead of: .modal(show), you need to do: .modal({show:true}), which initializes the modal instance, and then sets it to display by default. So:
<script type=\"text/javascript\"> jQuery(document).ready(function() { jQuery('#myModalId').modal({show:true}); }); </script> You can also set other settings for the modal within those {}. See Bootstrap's Model Doc for setting details.
try specifing the value in the form which will act as default value
<div class="input-group date" id='dob' name="dob" data-date-format="yyyy-mm-dd" > <input type="text" name="dob" id="dob" ***value="1940-01-01***" maxlength="20" class="form-control" required title="Please enter the date of birth"> <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> </div> and the script
<script type="text/javascript"> $(document).ready(function() { $('#dob').datepicker({ startDate: '1940-01-01', endDate: '-5d' }) }); </script
$('#myModal').modal('show');line and see if it get's called. If it gets called and you have no error in the script console then please put the whole source so we can see the whole picture..modal('show')on nothing.