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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:29:40+00:00 2026-06-11T04:29:40+00:00

I have a standard select box in my php form for my website containing

  • 0

I have a standard select box in my php form for my website containing a list of counties in the UK, an example of which is shown below:

<p class='form_title'>County<br>
    <select id="county" name="county">
        <optgroup label="England">
            <option>Bedfordshire</option>
            <option>Berkshire</option>
            <option>Bristol</option>

            ....

            <option>Wiltshire</option>
            <option>Worcestershire</option>
        </optgroup>

        <optgroup label="Wales">
            <option>Anglesey</option>

            ...

            <option>Radnorshire</option>
        </optgroup>

        <optgroup label="Scotland">
            <option>Aberdeenshire</option>

            ...

            <option>Wigtownshire</option>
        </optgroup>

        <optgroup label="Northern Ireland">
            <option>Antrim</option>

            ...

            <option>Tyrone</option>
        </optgroup>
    </select>
</p>

Once a user has submitted details, they can then edit them.

I therefore need a way to have selected the option that they previously chose, given that I have the option they chose saved in word form, such as Bedfordshire.

I know I need to add the word selected to one of the options, but I was wondering if there was a better way to do it than a massive case statement.

Thanks

  • 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-11T04:29:42+00:00Added an answer on June 11, 2026 at 4:29 am

    You should set an option value for each option to track the value.

    Also you should be generating that from a database and then you can set selected based on a $_GET or $_POST:

    for example:

    foreach($county as $name){
        $selected = '';
        if($name == $_GET['name']){
            $selected = ' selected="selected"';
        }
        echo '<option value="'.$name.'"'.$selected.'>'.$name.'</option>';
    }
    

    this doesn’t include your optgroup but that also should come from database.

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

Sidebar

Related Questions

I have a standard select box which I'm populating using jquery by appending options,
We currently have a form with the standard multi-select functionality of here are the
I have a requirement to add a standard drop-down from which you can select
I have a standard list view setup with backbone that looks something like below.
I have a query stored in MS Access which is doing a standard select
I have a standard kind of select list: <select> <option value=volvo>Volvo</option> <option value=saab>Saab</option> <option
I have the following dynamically created HTML block: <form class=standard settingsPage method=post enctype=multipart/form-data name=account
I have a standard select multiple HTML Input field, for example: <select multiple=multiple size=5
I have a standard JSF h:form which contains an h:SelectOneMenu control. As long as
I have a standard type of select list: <select> <option value=cars1>Cars 1</option> <option value=volvo>Volvo</option>

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.