...

View Full Version : Selected Drop Down Values



ringo
01-17-2005, 02:08 PM
while ($row = mysql_fetch_row($result))
{
$str .='<option value='.$row[0].'';
if ($row[0] == $UserID)
{
$str .='selected="selected"';
}
$str .= '>'.$row[1].'</option>';
}
echo $str;

My code is not working. I retrieved everything from the database. Let's say the drop down list has 10 values and UserID=4. But when I view the page, the 4th option is not selected. Instead the 1st option is selected. Why is that so?

glenngv
01-17-2005, 02:45 PM
It's more of a PHP question and definitely not Javascript. You should have posted it there. Ask the mod to move it and don't cross-post.

I don't know PHP but the first thing you need to do is to view the generated HTML source to check if the HTML for the dropdown is correct. You might be missing some quotes...

kyletxag
01-18-2005, 02:40 AM
In an html select you don't set selected="selected". You just put selected without quotes or anything within the brackets.

like



<select name="name">
<option value="value1">Value 1</option>
<option value="value2" selected>Value 2</option>
</select>

glenngv
01-18-2005, 03:19 AM
In an html select you don't set selected="selected". You just put selected without quotes or anything within the brackets.

like



<select name="name">
<option value="value1">Value 1</option>
<option value="value2" selected>Value 2</option>
</select>

In XHTML (http://www.w3schools.com/xhtml/xhtml_syntax.asp), attribute minimization is forbidden.

kyletxag
01-18-2005, 03:48 AM
i stand corrected.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum