I know how to populate one select box based on the option from another using jquery and ajax, but how do you do it when the select boxes are arrays?
默认情况下,页面上有 5 辆,但我也使用 .EnableMultiField() 根据需要添加更多行...在任何给定的一周,我们都会在库存中添加 10 到 30 辆汽车。
阿贾克斯:
$(".make").change(function() {
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax ({
type: "POST",
url: "get_models.php",
data: dataString,
cache: false,
success: function(html) {
$(".model").html(html);
}
});
});
PHP:
<ul>
<li><label for="year[]">Year</label><select name="year[]"><option></option>'.$Year.'</select></li>
<li><label for="year[]">Make</label><select name="make[]" class="make"><option></option>'.$Make.'</select></li>
<li><label for="year[]">Model</label><select name="model[]" class="model" style="width: 120px"><option></option>'.$Model.'</select></li>
<li><label for="trim[]">Trim</label><input type="text" size="10" name="trim[]" /></li>
<li><label for="vin[]">VIN</label><input type="text" name="vin[]"size="20" maxlength="17" onkeyup="return Upper(event,this)" /></li>
<li><label for="mileage[]">Mileage</label><input type="text" name="mileage[]" size="3" maxlength="6" /></li>
<li><label for="color[]">Color</label><select name="color[]"><option></option>'.$Color.'</select></li>
<li><label for="cost[]">Cost</label><input type="text" name="cost[]" size="6" maxlength="6" onchange="currency(this)" /></li>
<li><label for="asking[]">Asking</label><input type="text" name="asking[]" size="6" maxlength="6" onchange="currency(this)" /></li>
</ul>