Change value of jquery variable based on a select box
- by Nikos
I have a jquery datepicker script and what I want to do is to change "minDate: 10" value by a select box.
$(function() {
$('#hotel').change(function() {
// assign the value to a variable, so you can test to see if it is working
var selectVal = $('#hotel :selected').val();
if( selectVal == "hotel_c" ) {
var date = 10;
}
if( selectVal == "hotel_a" ) {
var date = 15;
}
if( selectVal == "hotel_b" ) {
var date = 6;
}
});
var dates = $('#from, #to').datepicker({
defaultDate: "+1w",
changeMonth: true,
dateFormat: 'yy-m-d',
minDate: 10,
numberOfMonths: 3,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate";
var instance = $(this).data("datepicker");
var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
});