This script has a static first drop down that does not change
For a dual dropdown both from a database – see here
dualdropdown.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> $(document).ready(function(){ $("#first-choice").change(function() { $("#second-choice").load("getter.php?choice=" + $("#first-choice").val()); }); }); </script> <select id="first-choice"> <option selected >Please Select</option> <option value="Dogs">Dogs</option> <option value="Cats">Cats</option> </select> <br /> <select id="second-choice"> <option>Please choose from above</option> </select> |
and the second file that does the database lookup, (must be called getter.php)
1 2 3 4 5 6 7 8 9 10 11 |
<?php include('cmdataconn.inc'); echo $choice = mysql_real_escape_string($_GET['choice']); $query = "SELECT * FROM pets WHERE client='$choice'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<option>" . $row{'petstuff'} . "</option>"; } ?> |
Petstuff should be the second lot of information that you want the second dropdown to be populated with.