Jump to content

dynamic drop down boxes


CincoPistolero

Recommended Posts

I need to create a form that when I select an option in a dropdown box, it takes the id from that item and uses that id to fill another drop down boxes selections. Getting the initial dropdown info with ID is easy, but I'm not sure how to get the other box to populate.

Below is my code for the drop downs. The first box is populating the correct data, but when something is selected, no matter what it is, the second box always shows the same thing.

Ideally, I'd like the second box either to not show up initially, or have it empty until something is chosen in the first dropdown.

[code]

<?php /* Size Information Query */
$querysize = " SELECT * FROM size where drumID=1 ORDER BY `sizeID` ASC LIMIT 0 , 30 ";
$resultsize = mysql_query($querysize) or die ("Error in query: $querysize. " . mysql_error());
?>
      <select name='size' onChange="if (document.myform.size.selectedIndex != 0) window.open(url = document.myform.size.options[document.myform.size.selectedIndex].value,'_self'); else alert('Please choose from menu.')">
        <option selected>Select Size</option><?php
        while ( $rowsize= mysql_fetch_array($resultsize)){extract($rowsize);
        echo "
        <option value='rhino_new.index.php?sizeID=$sizeID'>$sizeName</option>"
        ;}?>

      </select>
                                                                                    </td>
                    <td width="11%"><b><u><font face="Verdana" color="#ff9c31" size="2">FINISH: </font></u></b></td>
                                                                                    <td width="24%">                   
        <?php
if ($sizeID >0) { ?> 
<?php  /* Finish Information Query */
$queryfinish = " SELECT * FROM finish where sizeID='$sizeID' ORDER BY 'finishID' ASC LIMIT 0, 30 ";
$resultfinish = mysql_query($queryfinish) or die ("Error in query: $queryfinish. " . mysql_error());
?> 
<select name='finish' onChange="if (document.myform.finish.selectedIndex != 0) window.open(url = document.myform.finish.options[document.myform.finish.selectedIndex].value,'_self'); else alert('Please choose from menu.')">
        <option selected>Select Finish</option><?php
        while ( $rowfinish= mysql_fetch_array($resultfinish)){extract($rowfinish);
        echo "
        <option value='rhino_new.index.php?sizeID=$sizeID?finishID=$finishID'>$finishName - $price</option>"
        ;}?>

      </select>
      <?php } else { ?> &nbsp; <?php } ?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29739-dynamic-drop-down-boxes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.