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
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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.