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 ??? Link to comment https://forums.phpfreaks.com/topic/123088-solved-select-help/ 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/123088-solved-select-help/#findComment-635652 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"; Link to comment https://forums.phpfreaks.com/topic/123088-solved-select-help/#findComment-635655 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... Link to comment https://forums.phpfreaks.com/topic/123088-solved-select-help/#findComment-635676 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/123088-solved-select-help/#findComment-635680 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 Link to comment https://forums.phpfreaks.com/topic/123088-solved-select-help/#findComment-635682 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 ??? Link to comment https://forums.phpfreaks.com/topic/123088-solved-select-help/#findComment-635683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.