views:

28

answers:

1

Hi I am having a list box like this ,the list box is populated from the database

<td bgcolor="#FFFFCC">
<select name="listbox" id="FriendmailId" size="3" >
<option value="0">Select User From List</option>
<? foreach($searchfriend as $row)
{?>

<option value=""><?=$row['dEmailID'];?></option>
<? } ?>
</select>
</td>

The values are listed in the list box ....but the problem is when i select a item it is highted but not really selected why it is so

+4  A: 

You need to add selected="selected" for the option value you want selected:

<option value="" selected="selected"><?=$row['dEmailID'];?></option>

In a loop, this is usually done when a certain condition is met for an option to be selected (of course only one option can be selected at a time)

<? foreach($searchfriend as $row)
  if (condition to select a specific option value) // when true
  {
{?>    
<option value="" selected="selected"><?=$row['dEmailID'];?></option>
<? } else {  ?>
<option value=""><?=$row['dEmailID'];?></option>
<? }} ?>

Note: If you don't specify selected="selected" for an option, by default, first option value is selected.

Sarfraz
@actaually the data's are populated by ajax
udaya
@sarfraz again it is not selected
udaya
@sarfraz sorry i made a mistake it works great
udaya
i mis typed the name for the select box while posting
udaya
thanks you very much
udaya
@udaya: You are welcome :)
Sarfraz