bhakti_thakkar
12-23-2006, 08:30 AM
Hi all,
there is some stupid problem which i am not able to make out.i have a function to load months in a drop down. it loads properly but with a wrong seleted value.i am also passing the value which has to be selected by default but its not happening. i am not able to make it out :rolleyes:
below is my code:
<?
function DisplayMonths($field) {
print("<option value='N/A'>N/A</option>");
for ($i=1;$i<=12;$i++) {
if ($i==$field) {
$selected=' selected ';
}
switch ($i) {
case 1:
$mon="January";
break;
case 2:
$mon="February";
break;
case 3:
$mon="March";
break;
case 4:
$mon="April";
break;
case 5:
$mon="May";
break;
case 6:
$mon="June";
break;
case 7:
$mon="July";
break;
case 8:
$mon="August";
break;
case 9:
$mon="September";
break;
case 10:
$mon="October";
break;
case 11:
$mon="November";
break;
case 12:
$mon="December";
break;
} // end of switch
print("<option value=$i $selected>$mon</option>");
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<?$from=1;?>
<select name="from" class="sel1"><?=DisplayMonths($from);?></select>
</BODY>
</HTML>
there is some type caste problem??? please help me.December month gets selected instead of january
Thanks in advance
there is some stupid problem which i am not able to make out.i have a function to load months in a drop down. it loads properly but with a wrong seleted value.i am also passing the value which has to be selected by default but its not happening. i am not able to make it out :rolleyes:
below is my code:
<?
function DisplayMonths($field) {
print("<option value='N/A'>N/A</option>");
for ($i=1;$i<=12;$i++) {
if ($i==$field) {
$selected=' selected ';
}
switch ($i) {
case 1:
$mon="January";
break;
case 2:
$mon="February";
break;
case 3:
$mon="March";
break;
case 4:
$mon="April";
break;
case 5:
$mon="May";
break;
case 6:
$mon="June";
break;
case 7:
$mon="July";
break;
case 8:
$mon="August";
break;
case 9:
$mon="September";
break;
case 10:
$mon="October";
break;
case 11:
$mon="November";
break;
case 12:
$mon="December";
break;
} // end of switch
print("<option value=$i $selected>$mon</option>");
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<?$from=1;?>
<select name="from" class="sel1"><?=DisplayMonths($from);?></select>
</BODY>
</HTML>
there is some type caste problem??? please help me.December month gets selected instead of january
Thanks in advance