12-21-2015, 01:52 AM (This post was last modified: 12-21-2015, 05:04 AM by wolfgang1983.)
Currently on my modal form. I have 2 select drop down's.
Called year, month.
At the moment for the day I have to type it in.
What I would like to know is how am so that when I select a month it will populate the select day div with the correct number of days because some months shorter than others?
(12-21-2015, 01:52 AM)wolfgang1983 Wrote: What I would like to know is how am so that when I select a month it will populate the select day div with the correct number of days because some months shorter than others?
You could check this:
Code:
month = 1, 3, 5, 7, 8, 10, 12 => 31 days
month = 4, 6, 9, 11 => 30 days
month = 2 => if this year is leaf year => 29 days else 28 days
you should do this via javascript - it doesn't have much to do with CI, i think
if you use jquery you can try something like this (untested just wrote it down)
Code:
$('select[name="month"]').on("change", function()
{
var year = $('select[name="year"]').val();
if (year > 0)
{
$('select[name="day"]).find("option").remove();
var daysInMonth = new Date(year, $(this).val(), 0).getDate();
for(var i=1; i<=daysInMonth;i++)
{
$('select[name="day"]).append($("<option></option>").attr("value",i).text(i);
}
(12-21-2015, 04:31 AM)sintakonte Wrote: you should do this via javascript - it doesn't have much to do with CI, i think
if you use jquery you can try something like this (untested just wrote it down)
Code:
$('select[name="month"]').on("change", function()
{
var year = $('select[name="year"]').val();
if (year > 0)
{
$('select[name="day"]).find("option").remove();
var daysInMonth = new Date(year, $(this).val(), 0).getDate();
for(var i=1; i<=daysInMonth;i++)
{
$('select[name="day"]).append($("<option></option>").attr("value",i).text(i);
}
}
});
Not work did not display any days.
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!