0

I have an online form and I want to hide/display specific fields based on the date the user selects in a datepicker field. However, the date they select must fall within a specific date range in order for the additional fields to be shown/hidden.

Right now, this is the only code I have (I am not jQuery writer)

jQuery(document).ready(function ($) {
$("#dpick").datepicker("getDate");
var monthsWithExams;
monthsWithExams = $("#dpick").datepicker("getDate");

if monthsWithExams - THIS IS WHAT I NEED HELP FIGURING OUT
});

#dpick is the id of my datepicker field. Once they select a date, I want the code to check whether the selected date is inside a specific date range - for example, if they pick any day in December, then I want the form field with id tours to be hidden. I think I can write the if...else part, I just don't know how to check if date is inside date range.

I am not a jQuery expert so please try to explain it to me so that I can understand! Thanks for any help! :)

Iconoclast
  • 191
  • 1
  • 3
  • 12

2 Answers2

0

You can set the range by giving the minDate(starting date) and maxDate(Ending date)

 //This will only allow 30 days from now range
 $(function() {
   $("#txtFiled").datepicker({
   minDate: 'today',
   maxDate: "+30D"
   });
 }); 
Navajyoth CS
  • 968
  • 2
  • 7
  • 15
  • But won't this just limit the dates that can be selected within the datepicker to be between today's date and 30 days later? I don't want to limit the dates that can be chosen, I want to be able to check if the selected date is between December 1st 2013 and December 31st 2013 – Iconoclast Nov 26 '13 at 18:25
  • @Iconoclast please refer this http://stackoverflow.com/questions/16080378/check-if-one-date-is-between-two-dates-javascript – Navajyoth CS Nov 26 '13 at 19:40
0

The datepicker has an "onClose" which can take the chosen date and check it against other dates.

$( "#dpick" ).datepicker({
    onClose: function ( selectedDate ) {
        var date = selectedDate ;
        // if date is between x and y hide element A
    }
});