这可以根据第一个下拉菜单的结果动态创建第二个下拉菜单:
for (var i = 0; i < 1; i++) {
$('#wdiv' + i).change(function() {
var wdiv = $(this).val();
$.ajax({
type: "POST",
url: "populate_classes.php",
data: 'theOption=' + wdiv,
success: function(whatigot) {
$('#class_list' + i).html(whatigot);
}
}); //END $.ajax
}); //END dropdown change event
}
为什么下拉选择#wdiv0的输入会改变下拉菜单#class_list1?我希望#wdiv 选择设置#classlist0 下拉选择。
这是表格的一部分:
<fieldset><legend>Select Divisions</legend>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td><div align="center"><u><strong>Name</strong></u></div></td>
<td><div align="center"><u><strong>Division</strong></u></div></td>
<td><div align="center"><u><strong>Class</strong></u></div></td>
</tr>
<?php for ($i = 0; $i < $wrestlerkey; $i++) {
$sql = 'SELECT * FROM tourn_division AS td WHERE t_num = ?';
$divresult = $dbConnect->fetchAll($sql, $_SESSION['tourn_id']);
$divcount = count($divresult);
?>
<tr>
<td width="20%" bgcolor="#CCCCCC"><div align="right"><?php echo $_SESSION['wfirst'][$i] . " " . $_SESSION['wlast'][$i] . ":"; ?></div></td>
<td>
<select name="<?php echo "wdiv" . $i ?>" id="<?php echo "wdiv" . $i ?>">
<?php for ($d = 0; $d < $divcount; $d++) { ?>
<option value="<?php echo $divresult[$d]->div_num; ?>"><?php echo $divresult[$d]->div_name; ?></option>
<?php } ?>
</select></td>
<td>
<div id="<?php echo "class_list" . $i ?>"></div>
</td>
</tr>
<?php } ?>
</table>
</fieldset>