Forum Moderators: coopster

Message Too Old, No Replies

saving details from a drop down

saing the information from a drop down in the form tag using select

         

Ben3003

12:36 am on Jan 17, 2005 (gmt 0)



Hi all,
i have a simple form that contains users information, when people arrive at this site, i want it to display the current values in the fields, this i can do with text box's however with drop down lists it proves to be difficult. the following is the code i am using, however it isn't working. Any Ideas? Thanks in advance, Ben

<td>Office Loc:</td>
<td><font color="#FFFFFF" face="Tahoma">
<select name="OfficeID" value="<?php echo $row[OfficeID];?>" >
<option value="OfficeID"<?php echo (($row[OfficeID] == "1")? "selected" : "");?>>1</option>
<option value="OfficeID"<?php echo (($row[OfficeID] == "2")? "selected" : "");?>>2</option>
</select>
</font></td>

dreamcatcher

9:08 am on Jan 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ben3003,

Welcome to WebmasterWorld. Your select name and option fields all have the same name or value. Try this:


<td>Office Loc:</td>
<td><font color="#FFFFFF" face="Tahoma">
<select name="OfficeID">
<option value="1"<?php echo (($row['OfficeID'] == "1")? " selected" : "");?>>1</option>
<option value="2"<?php echo (($row['OfficeID'] == "2")? " selected" : "");?>>2</option>
</select>
</font></td>

I have used apostrophes in the SQL syntax, but it should be ok without. I have also added a space after 'selected'. Sometimes this can cause a problem.

dc