FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


set selected value in drop down





md7dani
I have a drop down menu with the values of the days in a month. The thing is that selected value is the first in the month. I want it to be todays date:

$today_d = date("d"); // I want this to be the selected value not 01

//write the select box of days
function writeDay(){
echo("<select name=\"".$this->objname."_day\" id=\"".$this->objname."_day\" onChange=\"javascript:tc_setDay('".$this->objname."', this[this.selectedIndex].value, '$this->path');\" class=\"tcday\">");
echo("<option value=\"00\">Day</option>");

for($i=1; $i<=31; $i++){
$selected = ((int)$this->day == $i) ? " selected" : "";
echo("<option value=\"".str_pad($i, 2 , "0", STR_PAD_LEFT)."\"$selected>$i</option>");
}
echo("</select> ");
}

I've tried to change values in the function but without any result.
md7dani
OK found that this will work:

$selected = (26 == $i) ? " selected" : "";

but i need to use:

$selected = ($today_d == $i) ? " selected" : ""; or $selected = ((int)$today_d == $i) ? " selected" : "";

None of them work.

For me it should work with one of them, don't understand why it doesn't?
thnn
date("d") will return the day with leading zeros, i.e. 01 instead of 1
Use date("j") instead

Also try putting $selected outside the quotes i.e. ".$selected."
Related topics
Drop down menu things
[JS] selecting an option from a drop down box
Javascript Drop down menus
Question About Drop-Down search buttons
drop down menus
Imagine:What you would do if Frihost drop down?
I need a Drop Down Bar Paying 100 FRIH$
help on a drop down menu!! Please Read!!
IP => Country => Drop Down Box!
Drop down Menu
FRIH$ For a dropdown navbar
Looking for Drop Down and Tab Menu Effects
extra line from css in drop down menu
"Drop Down List Box" Using PHP and MySql
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.