I have a button which sets the datepicker to tomorrow using the following code:
<!-- language: lang-js -->$("#txtDateOfJourney").datepicker({ startDate: '+1d'});
But it's not working.
Any Ideas?
I have a button which sets the datepicker to tomorrow using the following code:
<!-- language: lang-js -->$("#txtDateOfJourney").datepicker({ startDate: '+1d'});
But it's not working.
Any Ideas?
You only pass in the options (as in datepicker({ startDate: '+1d'})
) when you're initializing the controller. Since it's already initialized you don't need to do that. Instead you want to use the setDate()
method and then pass in <del>the javascript date representation of tomorrow</del> a string representing the relative date like this:
$('#txtDateOfJourney').datepicker('setDate', "+1d");
$('#btnTomorrow').click(function() {
$('#txtDateOfJourney').datepicker('setDate', "+1d");
});
<!-- language: lang-html -->
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/js/bootstrap-datepicker.js"></script>
<input type="text" id="txtDateOfJourney" class="datepicker" />
<button type="button" id="btnTomorrow" class="btn btn-info">Tomorrow</button>
<!-- end snippet -->