[英]Ajax form, 2 drop downs with external source
is there a way once I select from a drop down list on a form that it will select all models from the first dropdown in a second drop down 有没有一种方法,一旦我从表单的下拉列表中选择,它将在第二个下拉列表中从第一个下拉列表中选择所有模型
Here is my code 这是我的代码
<form>
<div class="landing_quote_left">
<table cellpadding="0" cellspacing="8" border="0">
<tr>
<td>
<label for="ajax_make_id" class="landing_quote_label">Make:</label>
</td>
<td>
<span id="ajax_make_select"><select name="2f_make_id" id="ajax_make_id" style="width: 170px;" onchange="Landing.getMakeFace(this.value);"><option value="999">Select a Make</option><option value="1">Acura</option><option value="2">Audi</option</select></span>
</td>
</tr>
<tr>
<td>
<label for="ajax_model_id" class="landing_quote_label">Model:</label>
</td>
<td>
<span id="ajax_model_select">
<select name="2f_model_id" id="ajax_model_id" style="width: 170px;" onchange="Landing.getModelFace(this.value);">
<option value="">Loading...</option>
</select>
</span>
</td>
</tr>
</table>
</div><!-- END landing_quote_left -->
</form>
So if I select Acura, the second drop down will show a list of all models ie MDX RDX RL TL TSX ZDX 因此,如果我选择Ac歌,第二个下拉列表将显示所有型号的列表,即MDX RDX RL TL TSX ZDX
If possible, how would I have both dropdowns load from different files. 如果可能的话,如何从不同文件加载两个下拉菜单。 {php or xml or whatever else is possible}
{php或xml或其他可能的方法}
Thanks for your time! 谢谢你的时间!
Here's some rough code on how to accomplish this. 这是一些有关如何完成此操作的粗略代码。
On page load, populate dropdown1. 在页面加载时,填充dropdown1。
$(function(){
$.get('file1.php', function(data){
$('#dropdown1').html( data );
});
// on change of dropdown1 populate dropdown2 with the respective data
$('#dropdown1').change(function(){
$.get('file2.php',{ make: $(this).val() }, function(data){
$('#dropdown2').html( data );
});
});
});
So in your file2.php you can check the $_GET
array for the make
variable passed in, then you can send back all the options for that model. 因此,在您的file2.php中,您可以检查
$_GET
数组中传入的make
变量,然后可以发送回该模型的所有选项。 You could also send back json instead of html but this gives you a rough idea of how to do it and i think it's best to keep it simple at first. 您也可以发送回json而不是html,但这为您提供了一个大概的实现方法,我认为一开始最好保持简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.