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

  • Home
  • SEARCH
  • 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 6388177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:14:48+00:00 2026-05-25T03:14:48+00:00

I have 5 drop down lists and a submit button. Every content of the

  • 0

I have 5 drop down lists and a submit button. Every content of the drop down list is depend on the selection value of the previous drop down list. I would like to make sure that the selected value for the every drop down list remain selected even after the submit button is being clicked. Can anyone help me in this?
I saw a site that does that but was made in ASP.NET, i prefer tu use PHP, javascript

<script type="text/javascript">
function changeSelect(lang, num, valueElement, nameSelect, nameSpan, dataSup, endId){
    var boxName =  document.getElementById(nameSelect);
    var hackIeSpan =  document.getElementById(nameSpan);
    var contentOption = $.ajax({
          url: "select.php",
          global: false,
          type: "POST",
          data: {
                 lang : lang,
                 num : num,
                 select : valueElement,
                 dataSup : dataSup,
                 endId : endId
             },
          dataType: "html",
          async:false,
          success: function(msg){
        }
       }
    ).responseText;
    hackIeSpan.innerHTML = contentOption;
}

<form id="searchForm" method="post" action="search.php?search&page=0&lang=<?php echo $lang; ?>">
            <fieldset>

                <select name="sort" onchange="changeSelect('<?php echo $lang; ?>', 1, this.value, 'type_list', 'hackIeType', 'null', 'null'); return true;">
                    <option value="0"><?php echo trad('SEARCH_01', $lang); ?></option>
                    <option value="Rental"><?php echo trad('SEARCH_01a', $lang); ?></option>
                    <option value="Sale"><?php echo trad('SEARCH_01b', $lang); ?></option>
                </select>

                <span id="hackIeType">
                    <select name="type_list">
                        <option value="0"><?php echo trad('SEARCH_04', $lang); ?> ...</option>
                    </select>
                </span>

…….

<span id="hackIeSleeps">
                    <select name="bedrooms">
                        <option value="0"><?php echo trad('SEARCH_05', $lang); ?> ...</option>
                    </select>
                </span>
                <span id="spanEndId">
                    <input id="endId" name="endId" type="hidden" value="" /> 
                </span>

                <input id="submit_search_home" type="submit" value="<?php echo trad('BTNSEARCH', $lang); ?>" />

            </fieldset>
  • 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-25T03:14:49+00:00Added an answer on May 25, 2026 at 3:14 am

    What happens when you press the submit button? Do you end up back on the same page? You just need to give the required option a selected="selected" attribute, based on the values sent in $_POST.

    As an example (this may not work for you, depending on exactly what happens when you press submit):

    <form id="searchForm" method="post" action="search.php?search&page=0&lang=<?php echo $lang; ?>">
      <fieldset>
        <select name="sort" onchange="changeSelect('<?php echo $lang; ?>', 1, this.value, 'type_list', 'hackIeType', 'null', 'null'); return true;">
          <option value="0"<?php if ($_POST['name'] === '0') echo ' selected="selected"'; ?>><?php echo trad('SEARCH_01', $lang); ?></option>
          <option value="Rental"<?php if ($_POST['name'] == 'Rental') echo ' selected="selected"'; ?>><?php echo trad('SEARCH_01a', $lang); ?></option>
          <option value="Sale"<?php if ($_POST['name'] == 'Sale') echo ' selected="selected"'; ?>><?php echo trad('SEARCH_01b', $lang); ?></option>
        </select>
        <span id="hackIeType">
    <?php
    
      if ($_POST['name'] === '0') {
       // The first select value is default, so we can just output a standard select
       // to be populated by AJAX
    
    ?>
          <select name="type_list">
            <option value="0"><?php echo trad('SEARCH_04', $lang); ?> ...</option>
          </select>
    <?php
    
      } else {
       // The first select is populated, so copy the logic that generates your second
       // select from 'select.php' and put it here, then output it
      }
    
    ?>
       </span>
    

    …….

        <span id="hackIeSleeps">
    <?php
    
      if ($_POST['type_list'] === '0') {
       // The second select value is default, so we can just output a standard select
       // to be populated by AJAX
    
    ?>
          <select name="bedrooms">
            <option value="0"><?php echo trad('SEARCH_05', $lang); ?> ...</option>
          </select>
    <?php
    
      } else {
       // The second select is populated, so copy the logic that generates your third
       // select from 'select.php' and put it here, then output it
      }
    
    ?>
        </span>
        <span id="spanEndId">
          <input id="endId" name="endId" type="hidden" value="" /> 
        </span>
        <input id="submit_search_home" type="submit" value="<?php echo trad('BTNSEARCH', $lang); ?>" />
      </fieldset>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a drop-down list like: <select id='list'> <option value='1'>Option A</option> <option value='2'>Option
I have a form, that includes a drop down list, and a submit button.
I have a form with a drop down list of venues and a submit
I have a page with 2 dropdrownlists & a submit button. I would like
I have three cascaded drop down lists. ddlIllnessType, ddlIllnessSubType and ddlInfectiousAgent Initially, only ddlIllnessType
I have a user control in a master page with two drop down lists.
I have a drop-down list with known values. What I'm trying to do is
I have a drop down list where users can select a theme for the
I have a drop down list that has options that need to be passed
I have a drop down list that triggers an updatepanel when the index is

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.