Problem with drop down menu and textfield

Hi there, I plan to create a drop down menu for user to choose their race but I know I could now list all the race in the list. So, I think to
create a textfield for them to state their race. But once the textfield is created, the drop down menu seems not working anymore. It shows empty when the users left the textfield empty even they choose their race in the drop down menu.

Here’s the code


<tr>
  <td width="166" height="21"><strong style="color: #FFFFFF;">&nbsp;&nbsp;Race</strong></td>
  <td width="12" height="21"><strong style="color: #FFFFFF;">:</strong></td>
  <td width="640" height="21">
  <strong id="spryselect1">
  <label>
  <select style="color: #009; font-family: Verdana, Geneva, sans-serif; font-size: 11px;"name="student_race" id="student_race">
  <option value="Malay" <?php if (!(strcmp("Malay", $row_student['student_race']))) {echo "selected=\\"selected\\"";} ?>>Malay</option>
  <option value="Chinese" <?php if (!(strcmp("Chinese", $row_student['student_race']))) {echo "selected=\\"selected\\"";} ?>>Chinese</option>
  <option value="Christian" <?php if (!(strcmp("Christian", $row_student['student_race']))) {echo "selected=\\"selected\\"";} ?>>Indian</option>
  <option value="Other" <?php if (!(strcmp("Other", $row_student['student_race']))) {echo "selected=\\"selected\\"";} ?>>Other</option>
  </select>
  </label>
  </strong>

  </td>
</tr>
<tr>
  <td height="21">&nbsp;</td>
  <td height="21">&nbsp;</td>
  <td height="21">If Other, please state :<strong id="sprytextfield3">
<label>
<input style="color: #009; font-family: Verdana, Geneva, sans-serif; font-size: 11px;" name="student_race" type="text" id="student_race" value="<?php echo $row_student['student_race']; ?>" size="40" maxlength="100" />
</label>
</strong></td>
</tr>

Please advise. Thank you.

You can’t use the same name="student_race" on two or more form elements. It needs to be unique to the input, or the script will get messed up. Just choose a different name.

Also, browsers may forgive you, but you shouldn’t use an id more than once, either.

Off Topic:

I’m not sure you’d get away with asking someone’s “race” where I live. Perhaps “nationality” or “ethnic background”, but “race” has some pretty dodgy associations … and, at least from a scientific point of view, is meaningless.

I change the name and id in

<label>
<input style="color: #009; font-family: Verdana, Geneva, sans-serif; font-size: 11px;" name="student_race" type="text" id="student_race" value="<?php echo $row_student['student_race']; ?>" size="40" maxlength="100" />
</label>

to ‘student_race1’. The dropdown menu now working fine but when user choose ‘other’ from dropdown and they type their race in the textfield, ‘other’ is displayed instead of the race they have typed.

Don’t forget to update this bit to the new name:

value="<?php echo $row_student['student_race']; ?>"

It sounds like you haven’t changed that to [‘student_race1’], in which case it’s echoing the result from the select list.