I've explored maybe 30 threads and my problem still isn't solved.
I have a JQuery datepicker:
<input id="datepicker" name="date" class="mydatepicker" onchange="isValidDate()"></input>
I simply want to write a javascript function that accomplishes this when called:
<script type="text/javascript">
document.getElementById("datepicker").value = 'certain date';
</script>
datepicker is tied to these files:
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
If you want to set a value for an input type 'Date', then it has to be formatted as "yyyy-MM-dd" (Note: capital MM for Month, lower case mm for minutes). Otherwise, it will clear the value and leave the datepicker empty.
By default DatePicker has standard height and width (height: '30px' and width: '143px'). You can change this height and width by using height and width property respectively.
For most datepickers, simply set data-provide="datepicker" on the element you want to initialize, and it will be intialized lazily, in true bootstrap fashion. For inline datepickers, use data-provide="datepicker-inline" ; these will be immediately initialized on page load, and cannot be lazily loaded.
You need to use the setDate
function of the datepicker
library. Try this:
$('#datepicker').datepicker('setDate', new Date()); // = set to today
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With