Jump to content

[SOLVED] select help


sasori

Recommended Posts

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

<?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

$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

<?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

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

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

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.