Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:12:00+00:00 2026-06-02T02:12:00+00:00

I have a select box where the user chooses a sex (gender) from a

  • 0

I have a select box where the user chooses a sex (gender) from a drop down, and their choice is specified with “selected” in the select tag. But the box always ends up ‘Choose’. What is wrong in the following syntax?

echo"<select name='sex'>
<option value='N' '". ($info['sex'] == "N" ? 'selected=selected':'') ."'>Choose</option>
<option value='M' '". ($info['sex'] == "M" ? 'selected=selected':'') ."'>Male</option>    
<option value='F' '". ($info['sex'] == "F" ? 'selected=selected':'') ."'>Female</option> 
</select>";

The $info['sex'] is from a consult SQL that return always N, M or F.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:12:02+00:00Added an answer on June 2, 2026 at 2:12 am

    Your selected=selected is being quoted and output like

    <option value='N' 'selected=selected'>
    

    when you run your code, use this

    echo"<select name='sex'>
    <option value='N' ". ($info['sex'] == "N" ? 'selected=\'selected\'':'') .">Choose</option>
    <option value='M' ". ($info['sex'] == "M" ? 'selected=\'selected\'':'') .">Male</option>    
    <option value='F' ". ($info['sex'] == "F" ? 'selected=\'selected\'':'') .">Female</option> 
    </select>";
    

    notice the escaped quotes at 'selected=\'selected\'' and the lack of single-quotes at ". ($info['sex'] and .">

    demo: http://codepad.org/AX95BzTR

    here’s a fiddle showing your problematic output: http://jsfiddle.net/JKirchartz/KB4rv

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the user to click the select box and when have selected any
I have a simple select box. When the user chooses an option, an image
I have the following multi-select box in a HTML form, where user can select
I have a dropdown box where the user can select a method to check
I have a select box that is being populated dynamically from a database. As
I have a select box that gets cloned. I want to remove the user's
So I have this select tag pulling a collection of pages for the user
I have a drop-down list box and two text fields of id values namely
Just wanna ask u guys here, I have a drop down list box which
I have a read only combo-box with 5 values in, when the user selects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.