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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:17:36+00:00 2026-06-04T04:17:36+00:00

original question: <select> dropdown output my MYSQL data properly using JS function I tried

  • 0

original question: <select> dropdown output my MYSQL data properly using JS function

I tried to write a follow-up but added this as an answer instead. Here’s my question:

using a similar/identical script to MassiveAttack; My problem is that once I select the second the dropdown, the 2 dropdowns reset themselves(the URL is correct); how do I ‘keep’ my values there?

here’s my script:

    function reload(form) {
        var val=form.cat.value;
        var val2=form.subcat.value;
        self.location='dd.php?cat=' + val + '&subcat=' + val2;
     }

     </script>
     </head>

     <body>
     <?

    @$cat = $_GET ['cat']; // Use this line or below line if register_global is off
    if (strlen ( $cat ) > 0 and ! is_numeric ( $cat )) { // to check if $cat is
                                                 // numeric data
                                                 // or not.
     echo "Cat Data Error";
     exit ();
     }

    $quer2 = mysql_query ( "SELECT DISTINCT name,category_id FROM shop_categories order by name" );

// ///// for second drop down list we will check if category is selected else we
// will display all the subcategory/////
    if (isset ( $cat ) and strlen ( $cat ) > 0) {
     $quer = mysql_query ( "SELECT name,product_id,priority,description FROM products WHERE category_id=$cat order by name" );
    } else {
    $quer = mysql_query ( "SELECT name,product_id,priority,description FROM products order by name" );
    }
// //////// end of query for second subcategory drop down list box
    echo "<form method=post name=f1 action='dd-check.php'>";
// / Add your form processing page address to action in above line. Example
// action=dd-check.php////
// //////// Starting of first drop downlist /////////
    echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select      Category</option>";
     while ( $noticia2 = mysql_fetch_array ( $quer2 ) ) {
         if ($noticia2 ['category_id'] == @$cat) {
             echo "<option selected value='$noticia2[name]'>$noticia2[name]</option>" . "<BR>";
          } else {
          echo "<option value='$noticia2[category_id]'>$noticia2[name]</option>";
          }
     }
          echo "</select>";
// //////////////// This will end the first drop down list ///////////

// //////// Starting of second drop downlist /////////
      $myList1 = array ();
      echo "<select name='subcat' onchange=\"reload(this.form)\"><option value=''>Select   subCategory</option>";
     while ( $noticia = mysql_fetch_array ( $quer ) ) {
          if ($_GET ['subcat'] == $noticia [subcat]) {        
          echo "<option value='$noticia[name]'>$noticia[name]</option>";
          }
     }
     echo "</select>";

     echo "<input type=submit value=Submit>";
     echo "</form>";
     ?>

    </body>

     </html>

    > 
  • 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-04T04:17:37+00:00Added an answer on June 4, 2026 at 4:17 am

    You forgot to use selected on second dropdown.

    echo "<option selected value='$noticia[name]'>
    

    Does it work when you change first dropdown?

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

Sidebar

Related Questions

Edit: original question below, but I revise it now that I have some code
Jeff Atwood asked the original question about parameterizing a SQL IN clause , but
This question is sort of a follow-up to my original question here . Let's
UPDATE: This question is out of date, but left for informational purposes. Original Question
Original Question: I am currently using Zend Framework with Zend_Db_* , and I am
UPDATED - please read further details below original question I have a select form
UPDATE 4: print_r( $data ); returns the data I posted in the original question,
ORIGINAL QUESTION: declare @num as int set @num = 5 select top @num col1,
NOTE: the original question is moot but scan to the bottom for something relevant.
This originates from my original question . I'm expanding on it. Html select options

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.