Click to See Complete Forum and Search --> : The JavaScript Source: Forms: True Date Selector does not work correctly
jm1383
06-09-2005, 11:15 AM
This script does not work correctly, even on it's description site. The URL is:
http://javascript.internet.com/forms/true-date-selector.html
This is the only place I could see to provide bugs about scripts from that site. The problem with the script is that when you choose a month with fewer days than other months (eg Feb) then select a month with more days, it stays at the lower number of days.
Thanks,
Jeff
jm1383
06-09-2005, 11:24 AM
After some research it's a Firefox issue with (I believe) the following line:
DaysObject.add(NewOption);
It does seem to be a Firefox issue. I have edited another script that should help you out. Try this:
<script type="text/javascript">
<!-- Begin
function populate(inForm)
{
var temp=0;
var today= new Date();
var day= today.getDate();
var month= today.getMonth();
var year= today.getFullYear();
var t2=10; // change to the total number of years to be displayed
for (var i=0; i <31 ; i++)
{
var x= String(i+1);
inForm.day.options[i] = new Option(x,x);
}
for (var i=0; i <31 ; i++)
{
var d=0;
d=inForm.day.options[i].value;
if(d=day){
inForm.day.options[i].selected=true;
break;}
}
for (var i=0,j=year; i <t2 ; i++, j++)
{
var y= String(j);
inForm.year.options[i] = new Option(y,y);
}
for(var i=0;i<12;i++)
{
if(i=month)
{inForm.month.options[i].selected=true;
break;}
}
}
function populate2(inForm2)
{
var t3=0;
if(inForm2.month.options[1].selected)
t3=28;
else if(inForm2.month.options[8].selected||inForm2.month.options[3].selected||inForm2.month.options[5].selected||inForm2.month.options[10].selected)
t3=30;
else
t3=31;
for(i=0;i<31;i++){
inForm2.day.options[i]=null;
}
for (var i=0; i <t3 ; i++)
{
var x= String(i+1);
inForm2.day.options[i] = new Option(x);
}
}
// End -->
</script>
</head>
<body onLoad=populate(form1)>
<div align="center">
<FORM NAME="form1">
<p>
<b>Day</b> <SELECT NAME="day"></SELECT>
<b>Month</b> <SELECT NAME="month" onChange = populate2(form1)>
<Option value=0>January</Option>
<Option value=1>February</Option>
<Option value=2>March</Option>
<Option value=3>April</Option>
<Option value=4>May</Option>
<Option value=5>June</Option>
<Option value=6>July</Option>
<Option value=7>August</Option>
<Option value=8>September</Option>
<Option value=9>October</Option>
<Option value=10>November</Option>
<Option value=11>December</Option>
</SELECT>
<b>Year</b><SELECT NAME="year"></SELECT>
</FORM>
</div>