Seeker Seeker - 4 months ago 10
jQuery Question

datepicker multiple fields with logic to show month year only in few fields

he all i am using this function of datepicker which is ok but what i want it to do is only on id datepicker1 full callender show with date month and year but for the rest ids datepicker2 till datepicker11 only month and year shows with the done button. would appreciate your help on it

here is the bit of my code

<script>
$(function() {
$( "#datepicker1, #datepicker2, #datepicker3, #datepicker4, #datepicker5, #datepicker6, #datepicker7, #datepicker8, #datepicker9, #datepicker10,#datepicker11").addClass('datepicker');
$( ".datepicker" ).datepicker({ dateFormat: "dd-M-yy", changeMonth: true, changeYear: true, yearRange: "1947:" });
});
</script>

Answer

You can add class datepicker to all datepicker ids except for #datepicker1 and then do like:

$("#datepicker2, #datepicker3, #datepicker4, #datepicker5, #datepicker6, #datepicker7, #datepicker8, #datepicker9, #datepicker10,#datepicker11").addClass('datepicker');

$(".datepicker").datepicker({
    dateFormat: "M-yy",
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    yearRange: "1947:"
});
$(".datepicker").focus(function() {
    $(".ui-datepicker-calendar").hide();
    $("#ui-datepicker-div").position({
        my: "center top",
        at: "center bottom",
        of: $(this)
    });
});

$("#datepicker1").datepicker({
    dateFormat: "dd-M-yy"
});
Comments