I want to have the JQuery Datepicker open when the user clicks on an image. There is no input field where the selected date appears afterwards; I\'m just going to save the e
Having a hidden input field leads to problems with datepicker dialog positioning (dialog is horizontally centered). You could alter the dialog's margin, but there's a better way.
Just create an input field and "hide" it by setting it's opacity to 0 and making it 1px wide. Also position it near (or under) the button, or where ever you want the datepicker to appear.
Then attach the datepicker to the "hidden" input field and show it when user presses the button.
HTML:
CSS:
#date-button {
position: absolute;
top: 0;
left: 0;
z-index: 2;
height 30px;
}
#date-field {
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 1px;
height: 32px; // height of the button + a little margin
opacity: 0;
}
JS:
$(function() {
$('#date-field').datepicker();
$('#date-button').on('click', function() {
$('#date-field').datepicker('show');
});
});
Note: not tested with all browsers.