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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:33:46+00:00 2026-06-17T09:33:46+00:00

I am working on a PHP form today and I need some help with

  • 0

I am working on a PHP form today and I need some help with the <select> & <option> tags. What I want to do is take a value from $_GET that is already in the <option> list and have it display as the index. The way my form works is that a user selects a location and hits an update button. When the page submits, it sends the value through $_GET and then uses it to grab the correct info from a database. After looking at said info, they have the option to delete it which is where I would need it. The issue is they have to reselect the location in order to delete it. I need the value to stay selected.

For example, say the user clicks on NJ in the selection box and hits update. The page would submit and ,lets say, reviews for restaurants are displayed. I want the selection box to keep the value of NJ until the user changes it.

My quick fix was to use the following code at the beginning of the <option> list:

<?php
    if($_GET['chooseLocation'])
        echo "<option>$_GET['chooseLocation']</option>";
?>

The only downside to this is that it would show NJ twice.

1) Am I on the right track?

2) Since I am using $_GET and storing the info in the URL, should I use javascript to do this instead?

I looked through about 15 questions and none of them answered my question. If you think this is a repost or copy, please post the original in the comments so I can see it.

  • 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-17T09:33:47+00:00Added an answer on June 17, 2026 at 9:33 am

    I don’t know your entire code, only that little piece. The way I usually do this is by the selected attribute and with some sort of IDs of my items. I guess you are reading the information from a database and the information you maintain from page to page is the value of the option. I do something like this:

    <?php
    for( $i = 0; $i < count($options); ++$i ) {
        echo "<option";
        if( $_GET['chooseLocation'] && $_GET['chooseLocation'] == $options[$i] ) {
            echo "selected";
        }
        echo ">{$options[$i]}</option>";
    }
    ?>
    

    Alternatively you can assume that virtually every user has JavaScript nowadays. Thus you actually could do the same with JavaScript by “attaching” the selected attribute on DOM readiness or when the page has loaded (e.g. using jQuery). Of course there is still a minority that refuses to use JavaScript, but I have no statistics up right now.

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

Sidebar

Related Questions

I am working on some form coding in PHP, and I have everything working
I am working on a php form with some jquery, especially for the error
I have asked before for help to get my php form working inside an
I am working on a PHP form that allows a user to add rows
I have simple php validation form that is halfway working. If you leave the
I am working on a php program that requires javascript on every form control.
I have an email attachment form that is working fine when the <form action=processingtheformfile.php>
My form is working fine with the validations being done by PHP. I have
I am working on a simple contact form written in php and have almost
I am working on a signup form, I am using PHP and on my

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.