dropdown output using JS
<p>original question: <a href="http://stackoverflow.com/questions/7528390/select-dropdown-output-my-mysql-data-properly-using-js-function/10675281#10675281">&lt;select&gt; dropdown output my MYSQL data properly using JS function</a></p>

<p>I tried to write a follow-up but added this as an answer instead. Here's my question:</p>

<p>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?</p>

<p>here's my script:</p>

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

     &lt;/script&gt;
     &lt;/head&gt;

     &lt;body&gt;
     &lt;?

    @$cat = $_GET ['cat']; // Use this line or below line if register_global is off
    if (strlen ( $cat ) &gt; 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 ) &gt; 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 "&lt;form method=post name=f1 action='dd-check.php'&gt;";
// / Add your form processing page address to action in above line. Example
// action=dd-check.php////
// //////// Starting of first drop downlist /////////
    echo "&lt;select name='cat' onchange=\"reload(this.form)\"&gt;&lt;option value=''&gt;Select      Category&lt;/option&gt;";
     while ( $noticia2 = mysql_fetch_array ( $quer2 ) ) {
         if ($noticia2 ['category_id'] == @$cat) {
             echo "&lt;option selected value='$noticia2[name]'&gt;$noticia2[name]&lt;/option&gt;" . "&lt;BR&gt;";
          } else {
          echo "&lt;option value='$noticia2[category_id]'&gt;$noticia2[name]&lt;/option&gt;";
          }
     }
          echo "&lt;/select&gt;";
// //////////////// This will end the first drop down list ///////////

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

     echo "&lt;input type=submit value=Submit&gt;";
     echo "&lt;/form&gt;";
     ?&gt;

    &lt;/body&gt;

     &lt;/html&gt;

    &gt; 
</code></pre>
