嘿,我有多个下拉选项,我想抓住它的值。一般的想法是从每个单独的下拉列表中获取值以通过ajax调用。下面是3个代码片段。前两个是我想要收集的值,第三个是通过调用。任何帮助表示赞赏。谢谢。
<div id="year" class="dropdownmenu styled-select">
<label>Year:</label>
<select name="year" id="yearlist" onchange="getId(this.value);">
<option value="">Select Year</option>
<?php
$query = "select distinct(Year) from websitemasterlist order by Year ASC";
$results = mysqli_query($conn, $query);
foreach($results as $info) {
?>
<option value="<?php echo $info[Year]; ?>"><?php echo $info[Year]; ?></option>
<?php
}
?>
</select>
</div>
<div id="make" class="dropdownmenu styled-select">
<label>Make:</label>
<select name="make" id="makelist" onchange="getId2(this.value);">
<option value="">Select Make</option>
</select>
</div>
<div id="model" class="dropdownmenu styled-select">
<label>Model:</label>
<select name="model" id="modellist" onchange="getId3(this.value);">
<option value="">Select Model</option>
</select>
</div>
继承人收集这些信息的代码我想知道如何收集年份并在1更改时生成。
function getId(val){
jQuery.ajax({
method: "POST",
url: "http://comugg.com/getdata.php",
data: "year="+val,
success:function(data){
jQuery("#makelist").html(data);
}
});
}
答案 0 :(得分:1)
您可以像这样更改功能以发布更多数据。更多信息和jquery示例http://api.jquery.com/jquery.ajax/#example-0
function getId(val){
var modelVariable = $( '#model:selected' ).val();
jQuery.ajax({
method: "POST",
url: "http://comugg.com/getdata.php",
data: {
year : val,
make : makeVariable
},
success:function(data){
jQuery("#makelist").html(data);
}
});
}