sasori Posted September 7, 2008 Share Posted September 7, 2008 i created a drop down menu for "month" <?php $months = array(1 =>"January","February","March", "April","May","June", "July","August","September", "October","November","December"); $today = time(); $monthMO = date("M",$today); echo "<form action='process.php' method='POST'>"; echo "<select name='month'>"; for($n=1; $n<=12 ;$n++) { echo "<option value='$n' "; if(($monthMO == $n) && ($monthMO == $today)) { echo " Selected "; } echo "> $months[$n]\n</option>"; } echo "</select>"; echo "</form>"; ?> my question is how will you make the form select the month today as the default selected everytime i run the script...because as of this moment, that script default is january ??? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted September 7, 2008 Share Posted September 7, 2008 <?php $months = array("January","February","March","April","May","June","July","August","September","October","November","December"); echo "<form action='process.php' method='POST'>"; echo "<select name='month'>\n"; foreach ($months as $value){ echo "\t<option value='$value'"; if($value == date("F")) { echo " Selected"; } echo "> $months[$n]</option>\n"; } echo "</select>"; echo "</form>"; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 7, 2008 Share Posted September 7, 2008 $months = array( 1=>"January","February","March", "April","May","June", "July","August","September", "October","November","December" ); echo "<form action=\"process.php\" method=\"POST\">\n"; echo "<select name=\"month\">\n"; foreach ($months as $monthNum=>$monthName) { $selected = (date('n')==$monthNum) ? ' selected="selected"' : '' ; echo "<option value=\"{$monthNum}\"$selected>{$monthName}</option>\n"; } echo "</select>\n"; echo "</form>\n"; Quote Link to comment Share on other sites More sharing options...
sasori Posted September 7, 2008 Author Share Posted September 7, 2008 <?php $months = array("January","February","March","April","May","June","July","August","September","October","November","December"); echo "<form action='process.php' method='POST'>"; echo "<select name='month'>\n"; foreach ($months as $value){ echo "\t<option value='$value'"; if($value == date("F")) { echo " Selected"; } echo "> $months[$n]</option>\n"; } echo "</select>"; echo "</form>"; ?> am sorry sir,, but your code doesn't show the months inside the dropdown... Quote Link to comment Share on other sites More sharing options...
jonsjava Posted September 7, 2008 Share Posted September 7, 2008 forgot one thing: <?php $months = array("January","February","March","April","May","June","July","August","September","October","November","December"); echo "<form action='process.php' method='POST'>"; echo "<select name='month'>\n"; foreach ($months as $value){ echo "\t<option value='$value'"; if($value == date("F")) { echo " Selected"; } echo "> $value</option>\n"; } echo "</select>"; echo "</form>"; ?> Quote Link to comment Share on other sites More sharing options...
sasori Posted September 7, 2008 Author Share Posted September 7, 2008 forgot one thing: <?php $months = array("January","February","March","April","May","June","July","August","September","October","November","December"); echo "<form action='process.php' method='POST'>"; echo "<select name='month'>\n"; foreach ($months as $value){ echo "\t<option value='$value'"; if($value == date("F")) { echo " Selected"; } echo "> $value</option>\n"; } echo "</select>"; echo "</form>"; ?> working fine now thanks Quote Link to comment Share on other sites More sharing options...
sasori Posted September 7, 2008 Author Share Posted September 7, 2008 $months = array( 1=>"January","February","March", "April","May","June", "July","August","September", "October","November","December" ); echo "<form action=\"process.php\" method=\"POST\">\n"; echo "<select name=\"month\">\n"; foreach ($months as $monthNum=>$monthName) { $selected = (date('n')==$monthNum) ? ' selected="selected"' : '' ; echo "<option value=\"{$monthNum}\"$selected>{$monthName}</option>\n"; } echo "</select>\n"; echo "</form>\n"; this one is working fine as well...but i got confuse on the foreach body ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.