Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of datepicker?

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>
like image 301
bob Avatar asked Jul 03 '15 08:07

bob


People also ask

How do you set a date picker value?

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.

How do I change my Datepicker size?

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.

How do I initialize a Datepicker?

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.


1 Answers

You need to use the setDate function of the datepicker library. Try this:

$('#datepicker').datepicker('setDate', new Date()); // = set to today
like image 136
Rory McCrossan Avatar answered Oct 06 '22 18:10

Rory McCrossan