Reputation: 355
I am working with some JQuery/Javascript and HTML tags. I have a javascript document that sets the max/min values of an input tag in HTML5. I am able to set my min value just fine for both of my tags, but the max value is not being set. Does anyone see anything obivous I may be missing? I'm just a little confused as to why the min is being set fine but the max is not. Thanks for the help.
date.html
Start Date (mm/yyyy): <input type="date" id="start_date" min="" max="">
End Date (mm/yyyy): <input type="date" id="end_date" min="" max=""/>
date.js
//Last Valid/Year = 2014-06-01
//First Month/Year = 2012-11-01
//Max does not work even if I hard code it.
jQuery('#start_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + FirstMonth.toString() + "-" + "01"});
jQuery('#end_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + FirstMonth.toString() + "-" + "01" });
Upvotes: 0
Views: 4983
Reputation: 355
Oh my gosh, a really easy fix that took me literally all day. My last Valid year was 2014-6-30. But the max needs to be read in as a yyyy/mm/dd format. The fix was to add a 0 before the month if it is not october, december or november and to make sure that the day you are picking is a valid day in the month. I.E, I was reading in 2014-6-31, and there are not 31 days in June. So the final string needed to be read in as 2014-06-30 instead of 2014-6-31
jQuery('#end_date').attr({
"min": v.FirstYear.toString() + "-" + v.FirstMonth.toString() + "-" + "01",
"max": v.LastYear.toString() + "-" + "0" + v.LastMonth.toString() + "-" + "30",
"value": v.LastYear.toString() + "-" + "0" + v.LastMonth.toString() + "-" + "01"
});
Upvotes: 1
Reputation: 1963
use Firstmonth
instead of FirstMonth
"unknown variable used.this is problem."
jQuery('#start_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + Firstmonth.toString() + "-" + "01"});
jQuery('#end_date').attr({ "max": lastValidYear.toString() + "-" + lastValidmonth.toString() + "-" + "01", "min": FirstYear.toString() + "-" + Firstmonth.toString() + "-" + "01" });
Upvotes: 0