B
beguigne
Below is a snippet of a crude date picking routine for a form. I am a
novice at this so, I am hitting my head at why when I select the day,
the onChange event gives me a blank. What am I missing?
Regards,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ben McFarlin ([email protected]) -->
<!-- Web Site: http://sites.netscape.net/mcfarlin -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function populate(objForm,selectIndex)
{
timeA = new
Date(objForm.year.options[objForm.year.selectedIndex].text,
objForm.month.options[objForm.month.selectedIndex].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();
for (var i = 0; i < objForm.day.length; i++)
{
objForm.day.options[0] = null;
}
for (var i = 0; i < daysInMonth; i++)
{
objForm.day.options = new Option(i+1);
}
document.f1.day.options[0].selected = true;
}
function getYears() {
// You can easily customize what years can be used
var years = new Array(2005,2006,2007)
for (var i = 0; i < document.f1.year.length; i++)
{
document.f1.year.options[0] = null;
}
timeC = new Date();
currYear = timeC.getFullYear();
for (var i = 0; i < years.length; i++)
{
document.f1.year.options = new Option(years);
}
document.f1.year.options[2].selected=true;
}
window.onLoad = getYears();
// End -->
</script>
</head>
<body>
<center>
<form name=f1>
<table border=0>
<tr>
<td align=center>
<select name=year
onChange="populate(this.form,this.form.month.selectedIndex);">
<option value="05" selected>2005</option>
<option value="06">2006</option>
<option value="07">2007</option>
<option value="08">2008</option>
</select>
<select name=month onChange="populate(this.form,this.selectedIndex);">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name=day onChange="alert
(document.forms[0].day.options[document.forms[0].day.selectedIndex].value);">
<!-- ERROR -->
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
</select>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
novice at this so, I am hitting my head at why when I select the day,
the onChange event gives me a blank. What am I missing?
Regards,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ben McFarlin ([email protected]) -->
<!-- Web Site: http://sites.netscape.net/mcfarlin -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function populate(objForm,selectIndex)
{
timeA = new
Date(objForm.year.options[objForm.year.selectedIndex].text,
objForm.month.options[objForm.month.selectedIndex].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();
for (var i = 0; i < objForm.day.length; i++)
{
objForm.day.options[0] = null;
}
for (var i = 0; i < daysInMonth; i++)
{
objForm.day.options = new Option(i+1);
}
document.f1.day.options[0].selected = true;
}
function getYears() {
// You can easily customize what years can be used
var years = new Array(2005,2006,2007)
for (var i = 0; i < document.f1.year.length; i++)
{
document.f1.year.options[0] = null;
}
timeC = new Date();
currYear = timeC.getFullYear();
for (var i = 0; i < years.length; i++)
{
document.f1.year.options = new Option(years);
}
document.f1.year.options[2].selected=true;
}
window.onLoad = getYears();
// End -->
</script>
</head>
<body>
<center>
<form name=f1>
<table border=0>
<tr>
<td align=center>
<select name=year
onChange="populate(this.form,this.form.month.selectedIndex);">
<option value="05" selected>2005</option>
<option value="06">2006</option>
<option value="07">2007</option>
<option value="08">2008</option>
</select>
<select name=month onChange="populate(this.form,this.selectedIndex);">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name=day onChange="alert
(document.forms[0].day.options[document.forms[0].day.selectedIndex].value);">
<!-- ERROR -->
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
<option> </option>
</select>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>