The standard code for DatePicker is:
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<p>Date: <input type="text" id="datepicker"></p>
How to launch datepicker onclick event from inline HTML, I mean:
<input ... onclick="" >
and with no separate JS code?
I tried:
<p>Date: <input type="text" id="datepicker" onclick="$(function() {$('#datepicker').datepicker();});"></p>
But it's working only on second click.
How to make it work on first click?
After you create datepicker, open it this way:
$('#datepicker').datepicker('show')
Go to datepicker API docs look at methods tab, it's all there
<p>Date: <input type="text" id="dp" onclick="$('#dp').datepicker();$('#dp').datepicker('show');"></p>
That work by any chance?
I'm no expert, but I believe you were having to click it twice because the first click merely initialised it as a datepicker. After this initialising, it's behaving as a normal datepicker, regardless of the onclick.
Try this code:
<script>
$(function() {
$("#datepic").datepicker({ showOn: 'button',buttonImage: 'image/calendar.gif'});
});
</script>
<input type="text" id="datepic" />
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