Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to trigger jQuery datepicker element on both input click and button?

I have an input text containing a default date and I'm using jQuery's Datepicker plugin to select a date from a popin calendar. This calendar pops in when the user clicks on the small picture next to the input.

This is working great but I'd like to trigger the calendar's popin even when the user clicks on the input text. Long story short, I want the calendar to be displayed on both evenements.

Is it possible ? How ?

Thank you !

like image 348
Anth0 Avatar asked Dec 28 '10 15:12

Anth0


2 Answers

You just need to set the showOn option to "both" (rather than "focus" or "button"), like this:

$( "#datepicker" ).datepicker({
    showOn: "both",
    buttonImage: "calendar.gif",
    buttonImageOnly: true
});

You can try it out here.

like image 140
Nick Craver Avatar answered Oct 27 '22 01:10

Nick Craver


Try to trigger the button event in the input event handler, something lik ethat:

jQuery("#myinput").click(function(e){
    jQuery("#mybtn").trigger('click');
})
like image 29
regilero Avatar answered Oct 27 '22 01:10

regilero