samuel toh
samuel toh

Reputation: 7076

How do I set a Min and Max date for my datepicker?

Here is what i have tried so far :

Date of birth : <input id="date_of_birth" type="text" /><br />

My Javascript code is like this :

$(function(){

    $('#date_of_birth').datepicker({

        monthNames: [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" ],
        dayNames: [ "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" ],
        dayNamesMin: [ "M", "S", "S", "R", "K", "J", "S" ],
        //showOn: 'both',
        dateFormat: 'yy-mm-dd',
        changeMonth: true,
        changeYear: true,
        inline: true,
        yearRange: '-100:-12',
    });
});

Demo is like this : http://jsfiddle.net/oscar11/8w8v9/1133/

Any solution to solve my problem?

Thank you

Upvotes: 0

Views: 239

Answers (2)

Sarantis Tofas
Sarantis Tofas

Reputation: 5167

$(function(){

    $('#date_of_birth').datepicker({

      monthNames: [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" ],
      dayNames: [ "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" ],
      dayNamesMin: [ "M", "S", "S", "R", "K", "J", "S" ],
      dateFormat: 'yy-mm-dd',
      changeMonth: true,
      changeYear: true,
      inline: true,
      minDate: '-100Y',
      maxDate: '-12Y',
    }); 
});

more info on datePicker

Upvotes: 3

Kurohige
Kurohige

Reputation: 1418

this works for me

$(function(){
$('#date_of_birth').datepicker({
    //dateFormat: 'dd-mm-yy',
    //altField: '#thealtdate',
    //altFormat: 'yy-mm-dd'

    monthNames: [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" ],
            dayNames: [ "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" ],
            dayNamesMin: [ "M", "S", "S", "R", "K", "J", "S" ],
//                        showOn: 'both',
            dateFormat: 'yy-mm-dd',
            changeMonth: true,
            changeYear: true,
            inline: true,
            yearRange: (new Date().getFullYear() - 100)+":",
            maxDate: '-12y'



});});

Upvotes: 0

Related Questions