Click to See Complete Forum and Search --> : Need Help
Squid
January 17th, 2005, 09:09 AM
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?
bigBA
January 17th, 2005, 10:15 AM
from the first sight...
this is wrong:
$str .='selected="selected"';
it should be
$str .='selected';
becasue an selected option field looks like this:
<option value="mickey" selected>mouse</option>
AndyTower
January 19th, 2005, 12:08 AM
This is code work good
while ($row = mysql_fetch_row($result)) {
$str .='<option value="'.$row[0].'"';
if ($row[0] == $UserID) {
$str .=' selected';
}
$str .= '>'.$row[1].'</option>';
}
echo $str;
visualAd
January 19th, 2005, 08:05 AM
from the first sight...
this is wrong:
it should be
$str .='selected';
becasue an selected option field looks like this:
<option value="mickey" selected>mouse</option> No .. he's right. It should be selected="selected" as per the XHTML standard and also be used in HTML 4.
Squid: The reason it is not selected is because you have not put any whitespace between the value attribute. So it would look like this:
<option value="value"selected="selected">
You just need to modify your code slightly:
$str .=' selected="selected"'; // note the white space
bigBA
January 19th, 2005, 01:27 PM
well... right :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.