Hey all,
I'm having trouble with the following code:
Is there an easier way to do this?
Thanks,
- MT
I'm having trouble with the following code:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script>
<!--
function changeDate(){
switch(document.myForm.month.value) {
case "january":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30] == null) {
document.myForm.days.options[30] = new Option('30','30');
}
if (document.myForm.days.options[31] == null) {
document.myForm.days.options[31] = new Option('31','31');
}
alert(document.myForm.days.length);
break;
case "february":
document.myForm.days.options[28] = null;
document.myForm.days.options[28] = null;
document.myForm.days.options[28] = null;
document.myForm.days.options[28] = null;
alert(document.myForm.days.length);
break;
case "march":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30] == null) {
document.myForm.days.options[30] = new Option('30','30');
}
if (document.myForm.days.options[31] == null) {
document.myForm.days.options[31] = new Option('31','31');
}
alert(document.myForm.days.length);
break;
case "april":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
document.myForm.days.options[30] = null;
alert(document.myForm.days.length);
break;
case "may":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30] == null) {
document.myForm.days.options[30] = new Option('30','30');
}
if (document.myForm.days.options[31] == null) {
document.myForm.days.options[31] = new Option('31','31');
}
alert(document.myForm.days.length);
break;
case "june":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30]) {
document.myForm.days.options[30] = null;
}
if (document.myForm.days.options[31]) {
document.myForm.days.options[31] = null;
}
alert(document.myForm.days.length);
break;
case "july":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30] == null) {
document.myForm.days.options[30] = new Option('30','30');
}
if (document.myForm.days.options[31] == null) {
document.myForm.days.options[31] = new Option('31','31');
}
alert(document.myForm.days.length);
break;
case "august":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30] == null) {
document.myForm.days.options[30] = new Option('30','30');
}
if (document.myForm.days.options[31] == null) {
document.myForm.days.options[31] = new Option('31','31');
}
alert(document.myForm.days.length);
break;
case "september":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
document.myForm.days.options[30] = null;
alert(document.myForm.days.length);
break;
case "october":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30] == null) {
document.myForm.days.options[30] = new Option('30','30');
}
if (document.myForm.days.options[31] == null) {
document.myForm.days.options[31] = new Option('31','31');
}
alert(document.myForm.days.length);
break;
case "november":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
document.myForm.days.options[30] = null;
alert(document.myForm.days.length);
break;
case "december":
if (document.myForm.days.options[29] == null) {
document.myForm.days.options[29] = new Option('29','29');
}
if (document.myForm.days.options[30] == null) {
document.myForm.days.options[30] = new Option('30','30');
}
if (document.myForm.days.options[31] == null) {
document.myForm.days.options[31] = new Option('31','31');
}
alert(document.myForm.days.length);
break;
}
}
//-->
</script>
</head>
<body onLoad="alert(document.myForm.days.length);">
<form name="myForm" id="myForm">
<table width="25%" border="0" cellpadding="2" cellspacing="0">
<tr align="center">
<td>
<select name="month" onChange="changeDate()">
<option value="january" selected>January</option>
<option value="february">February</option>
<option value="march">March</option>
<option value="april">April</option>
<option value="may">May</option>
<option value="june">June</option>
<option value="july">July</option>
<option value="august">August</option>
<option value="september">September</option>
<option value="october">October</option>
<option value="november">November</option>
<option value="december">December</option>
</select>
</td>
<td>
<select name="days">
<option value="01" selected>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>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
Is there an easier way to do this?
Thanks,
- MT