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 8853601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:41:35+00:00 2026-06-14T13:41:35+00:00

From the database I pull back the user information and based on this I

  • 0

From the database I pull back the user information and based on this I can determine the correct index value using a case statement:

<?php
    $genderIndex = 0;
    switch ($displayProperties['gender']) 
    {
        case "":
            $genderIndex = 0;
            break;
        case "Male":
            $genderIndex = 1;
            break;
        case "Female":
            $genderIndex = 2;
            break;
        case "Other":
            $genderIndex = 3;
            break;
    }
 ?>

On the form I have an HTML dropdown (select):

<select name="gender" selectedIndex="<?php echo $genderIndex; ?>">
    <option value="0"> </option>
    <option value="Male">Male</option>
    <option value="Female">Female</option>
    <option value="Other">Other</option>
</select><br/>

The problem is it never works and always loads the page at index=0 and I made sure to verify if $genderIndex actually has the expected value (it does).

What am I doing wrong?

  • 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-14T13:41:36+00:00Added an answer on June 14, 2026 at 1:41 pm

    selectedindex property is not used in this way, for appropriate use of the selectedindex property you can view http://www.w3schools.com/jsref/prop_select_selectedindex.asp.

    Instead what you are after is applying the “selected” attribute to the appropriate option. The code below runs some shorthand if/else checks and will apply the “selected” attribute where appropriate, based on your $genderIndex you created in your function given.

    <select name="gender">
        <option value="0" <?php echo ($genderIndex==0)?('selected'):(''); ?>"> </option>
        <option value="Male" <?php echo ($genderIndex==1)?('selected'):(''); ?>>Male</option>
        <option value="Female" <?php echo ($genderIndex==2)?('selected'):(''); ?>>Female</option>
        <option value="Other" <?php echo ($genderIndex==3)?('selected'):(''); ?>>Other</option>
    </select><br/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pull back from a database JSON documents that are not based
I'd like to pull a value from my database and use it as the
I want to use jQuery to pull information from my database when I click
I'd like to be able to pull users from a database using either a
I am using the following code to pull in data from my database and
I pull markers' data from a MYSQL database using SQL and build up an
I'm trying to pull out information from a database with PHP and have the
I have jokes.db database. This database file imported from using this article., http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ .
I'm using Linq/EF4.1 to pull some results from a database and would like to
I want to pull data from a database to display into a ComboBox, and

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.