【发布时间】:2013-04-02 03:10:54
【问题描述】:
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>
【问题讨论】:
-
var dataString = \'id=\'+ id;。\'是来自真实代码还是只是问题中的一些错字? -
我复制并粘贴... jquery 代码被包装在 php 中,所以我转义了引号。此代码有效,但仅适用于第一个“make”字段
-
This code works, but only on the first "make" field。标记只有一个make[]字段。其他人在哪里? -
我只发了一个sn-p,其余的都在,只是没发。见:login.carcityofdanbury.com/New/01/add.php