Show/ hide dynamic combobox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • accessbeginerry
    New Member
    • Apr 2010
    • 8

    Show/ hide dynamic combobox

    I have two comboboxes which are generated by queries from mysql.

    When user choose value in first combobox i need to display second combobox, but if nothing is choosen second combox should not be displayed.
    The code:
    Code:
    <?php
    echo "<form method= \"post\" name=\"formcombo\" action=''>";
    echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Choose main category</option>";
    while($cat2 = mysql_fetch_array($query2)) {
    if($cat2['category_id']==@$category)
    {
    echo "<option value='$cat2[category_id]'>$cat2[category_name]</option></br>";}
    else
    {
    echo "<option value='$cat2[category_id]'>$cat2[category_name]</option>";
    }
    }
    echo "</select></br>";
    echo "<select name='subcat'><option value=''>Choose subcategory</option>";
    while($cat = mysql_fetch_array($query1)) {
    echo "<option value='$cat[subcat_name]'">$cat[subcat_name]</option>";
    }
    echo "</select>";
    echo "<input type=\"submit\" value =\"Submit\">";
    echo "</form>";
    ?>
    I use javascript to generate combobox values:

    Code:
    <script type="text/javascript">
    function reload(form){
    var val=form.cat.options[form.cat.options.selectedIndex].value;
    self.location='main.php?cat=' + val ;
    }
    </script>
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I don't see where you're trying to show or hide the combo box. Also, in your PHP file, you're not defining your queries anywhere. And if you're trying to make "dynamic" combo boxes, ie the values in one combo box change in accordance to the value in another combo box, then you should look into AJAX.

    Comment

    Working...