Derek Hutchinson Derek Hutchinson - 2 months ago 7
HTML Question

Populate Drop Dow List from Drop Down List

EDIT: This first post now contains working code and has the problem edited out of it.

I am making a web page that is populating a DDL from a SQL query. Upon selection it executes a 2nd SQL query to populate the second DDL. The script is firing and no errors are being raised but the 2nd DDL does not populate.

My code

<script src=""></script>
<script>$(function() {
$("#exchangenameselect").change(function() {
$("#jobnoselect").load("getter.php?choice=" + $("#exchangenameselect").val());
<!-- Perex -->
<div id="perex" class="box">
<?php $conn = mysqli_connect('host', 'user', 'pass', 'database')
or die ('Cannot connect to db');?>

<p><select id="exchangenameselect">

$result = $conn->query("select distinct Exchange from MasterJobTable");
while ($row = $result->fetch_assoc()) {
$exchange = $row['Exchange'];
echo '<option>'.$exchange.'</option>';
echo "\r\n";

Job Number:
<p><select id="jobnoselect">

</div> <!-- /perex -->

Code from getter.php is


$username = "user";
$password = "passs";
$hostname = "host";

$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("database", $dbhandle) or die("Could not select examples");
$choice = mysql_real_escape_string($_GET['choice']);

$query = "SELECT * FROM MasterJobTable WHERE Exchange='$choice'";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {
echo "<option>" . $row['JobNo'] . "</option>";

Getter.php is returning the data and the jQuery is doing something as can be seen at the site and getter can be directly accessed at

Does anyone have a possible explination why this doesn't work?


You aren't setting a value in

echo <option value="">'.$exchange.'</option>';

but you are querying it with ajax in

$("#jobnoselect").load("getter.php?choice=" + $("#exchangenameselect").val());

Try this:

echo <option value="'.$exchange.'">'.$exchange.'</option>';