rockdudex rockdudex - 1 year ago 93
jQuery Question

Hide incorrect days in droplist calendar

I'm quite new to web development and though I know I can use those calendar datepickers to input dates to a a form. I was wondering how can I hide or disable incorrect days from

droplists, like
30 february
31 april
. Is there a non obscure way to do that using javascript or jquery?
I'm thinking on this kind of datepicker.
See jsfiddle

Answer Source

Based on the answer from HERE, first add a few more classes to your drop-down lists and use JQuery this way:

$(document).ready(function () {
    $('.operator').on('change', function () {
    var daysx = Math.round(((new Date($('.year option:selected').val(), $('.month option:selected').val()))-(new Date($('.year option:selected').val(), parseInt($('.month option:selected').val())-1)))/86400000);

    $('.maindates option').remove();
    for (var i=1; i < (daysx + 1); i++) {
        $('.maindates').append('<option value="' + i + '">' + i + '</option>');

See my jsfiddle here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download