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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:41:59+00:00 2026-05-12T15:41:59+00:00

I have a form where the user selects field 1, and then selects field

  • 0

I have a form where the user selects field 1, and then selects field 2, which is populated by their choice on field 1.

The problem is that after they are on step 2, field 1 is not showing their choice (even though the selection is still carried in a hidden form field. Im not sure how to do that with the way ive setup the form below. i need to figure out how to mark it with the selected option.

The functions to selecting field 1 and 2 are below

function GetCategoryList(){
    $push .= "<form action=\"main.php\" method=POST>";
    $push .= "<select name=cat>";
    $result = mysql_query("SELECT * FROM `cats`") or trigger_error(mysql_error()); 
    while($row = mysql_fetch_array($result)){ 
        foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } 
            $id = $row['id'];
            $cat = $row['cat'];
            $push .= "<option value=$id>$cat</option>";
    }
    $push .= "</select>";
    $push .= "<input type=submit name=button id=button value=\"Set Category\"></form>";
    return $push;
}

function GetSubCategoryList($cat){
    $push .= "<form action=\"main.php\" method=POST>";
    $push .= "<select name=subcat>";
    $result = mysql_query("SELECT * FROM `subcats` WHERE cat = '$cat'") or trigger_error(mysql_error()); 
    while($row = mysql_fetch_array($result)){ 
        foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } 
            $id = $row['id'];
            $subcat = $row['subcat'];
            $cat = $row['cat'];
            $push .= "<option value=$id>$subcat</option>";

    }
    $push .= "</select>";
    $push .= "<input type=hidden name=cat value=$cat>";
    $push .= "<input type=submit name=button id=button value=\"Set Sub-Category\"></form>";
    return $push;
}

This is the code on the page itself

  Category
<? echo GetCategoryList(); ?>
  <br />

  SubCategory
<? if(isset($_POST['cat'])){ echo GetSubCategoryList($_POST['cat']); } else { echo "<em>select a category</em>"; } ?>
<br />
  • 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-05-12T15:41:59+00:00Added an answer on May 12, 2026 at 3:41 pm

    You need to mark the selected option with the selected attribute.

    function GetCategoryList($selectedId=null) {
    //...
        $selected = ($id==$selectedId) ? "selected" : "";
        $push .= "<option $selected value=$id>$cat</option>";
    //...
    }
    
    echo GetCategoryList(isset($_POST['cat']) ? $_POST['cat'] : null);
    

    (for xhtml it has to be selected="selected")

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

Sidebar

Related Questions

I have a form in which the user selects a few items to display
I have a form a user can enter their name, then it will add
i have a form that has a multiple select drop down. a user can
I have form where user submits field. Field can have letters, numbers, and punctuation.
in my application i have an form where user enter their username first .
I have a form allowing a user to signup for a news letter which
Friends, I'm converting an Oracle Form to Apex and have run into problem(s?) which
within a form I have a section that allows the user to build out
I have a form that requires a physical address. Once the user enters the
I have a drop down which builds a form based of the selections that

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.