SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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

    HTML 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.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,118
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    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.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    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.
    I change the name and id in
    HTML Code:
    <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.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,118
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by Php Beginner View Post
    'other' is displayed instead of the race they have typed.
    Don't forget to update this bit to the new name:

    PHP Code:
    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.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •