views:

294

answers:

4

Hello, I've already looked around but couldn't find the exact solution/problem I'm having right now.

All I want is to have the calendar appear either by clicking on the calendar icon AND from the text field in which the date appears when selecting a date. Right now, after trying different properties, I can only have the calendar appear by one or the other, but not both: the icon and the field.

This is the code I'm using to activate it via the icon:

$("#datepicker").datepicker({
   showOn: 'button',
   buttonImage: 'images/icon-calendar.gif',
   buttonImageOnly: true,
   changeMonth: true,
   changeYear: true,
   showAnim: 'slideDown',
   duration: 'fast'
});

Is there a way to have the calendar appear by clicking on the icon AND the field as well?

Thanks.

+1  A: 

Give your date picker field an id and try this:

<input type="text" name"whatever" id="datepickerfield" />

For the field:

$("#datepickerfield").datepicker({
 showOn: 'button',
 buttonImage: 'images/icon-calendar.gif',
 buttonImageOnly: true,
 changeMonth: true,
 changeYear: true,
 showAnim: 'slideDown',
 duration: 'fast'
});
Sarfraz
+1  A: 

try setting: showOn: 'both'

derek
Doh! So simple but there's no explanation of this in the plugin's page.Thanks a lot derek, it worked!I can't vote yet though :(, will vote for you once I have enough reputation points.
Ricardo Zea
no problem, this issue got me too when I first used datepicker.
derek
+1  A: 

This is the working code to make the calendar appear when clicking on the icon AND on the date field, notice the "both" value:

$("#datepicker").datepicker({
 showOn: 'both',
 buttonImage: 'images/icon-calendar.gif',
 buttonImageOnly: true,
 changeMonth: true,
 changeYear: true,
 showAnim: 'slideDown',
 duration: 'fast'
});

Thanks to derek for his help.

Ricardo Zea
A: 

Thank you all for the great tips. Much appreciated.

Suresh