I am using jQuery datepicker on 2 forms on the same page.
I currently am using the following code (below), but as you can see, I am using the same parameters over again (showOn, buttonImage, buttonImageOnly, dateFormat, & constrainInput)
Is there a more efficient way to do this rather then repeating myself over and over again, over 4 methods?
$('#startdate').datepicker(
{
showOn: 'both',
buttonImage: '/assets/images/calendar_symbol.png',
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
constrainInput: true, // All of the above is repeated again below
minDate: new Date(<?php echo date("Y")?>, <?php echo date("m")-1?>, <?php echo date("d")?>),
onClose: function()
{
$('#enddate').val($('#startdate').val());
}
}
);
$('#enddate').datepicker(
{
showOn: 'both',
buttonImage: '/assets/images/calendar_symbol.png',
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
constrainInput: true, // All the above repeated again..
minDate: new Date(<?php echo date("Y")?>, <?php echo date("m")-1?>, <?php echo date("d")?>)
}
);
$('#filter_startdate').datepicker(
{
showOn: 'both',
buttonImage: '/assets/images/calendar_symbol.png',
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
constrainInput: true,// and again...
onClose: function()
{
$('#enddate').val($('#startdate').val());
}
}
);
$('#filter_enddate').datepicker(
{
showOn: 'both',
buttonImage: '/assets/images/calendar_symbol.png',
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
constrainInput: true // and again....
}
);
I was thinking of using a if statement to check what was clicked (#startdate
or #filter_startdate
), and then breaking it down like that, but unsure if this would work or how to do this.
defaultOptions
object that contains all the common elements (showOn, buttonImage, buttonImageOnly, etc), then just modify it as necessary? \$\endgroup\$<?php echo date("Y")?>, <?php echo date("m")-1?>, <?php echo date("d")?>
instead of<?php echo date("Y").",".(date("m")-1).",".date("d"); ?>
? Just my 2c \$\endgroup\$