Akhil
Akhil

Reputation: 471

How to Set Max Date and min Date of a datepicker with dates specified inside a hidden field

I have a text control with datepicker assigned, i would like the datepicker to only display the dates between the dates specified inside two hidden fields.

 var mxDate = $('#hdnMaxDate').val();
 var mnDate = $('#hdnMinDate').val();
            $('#txtDate').datepicker({ dateFormat: 'dd/M/yy',
                altFormat: 'dd/mm/yy',
                minDate:mnDate,
                maxDate: mxDate
            });

<input type="text" id="txtDate" >
<input type="hidden" id="hdnMaxdate" value="24/09/2014">
<input type="hidden" id="hdnMindate" value="24/08/2014">

Upvotes: 1

Views: 2968

Answers (1)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Your code is already working, you have used wrong input hidden id in below code

var mxDate = $('#hdnMaxDate').val();
var mnDate = $('#hdnMinDate').val();

correct it to following (here d for date is in small letter)

var mxDate = $('#hdnMaxdate').val();
var mnDate = $('#hdnMindate').val();

Also correct date format to small 'm' as your input values are in dd/m/yy format.

$('#txtDate').datepicker({ dateFormat: 'dd/m/yy',

Demo

Upvotes: 2

Related Questions