所以这是场景.我有2次下降.第一个具有onchange
在第二个下拉列表中加载数据的功能.它完全正常工作,但我想使用该onchange
功能实现在第二个下拉列表中加载数据onload
.
这是我的功能:
function fetch_select(val)
{
$.ajax({
type: 'post',
url: '../function/fetch_car_package.php',
data: {
get_option:val
},
success: function (response) {
document.getElementById("new_select").innerHTML=response;
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的下拉菜单:
<select name='cItemID' onchange="fetch_select(this.value);">
<?php
$sql = "";
$sth = $dbh->prepare($sql);
$sth->execute();
$result = $sth->fetchAll();
foreach($result as $row) {
if ($_SESSION['cItemID'] == $row['Item ID']) {
$selected = "selected";
} else {
$selected = '';
}
echo "<option value='".$row['Item ID']."' $selected>".$row['Item Name']."</option>";
}
?>
</select>
Run Code Online (Sandbox Code Playgroud)
我的ajax处理页面:
if(isset($_POST['get_option'])){
$ItemID = $_POST['get_option'];
$sql = ""; …
Run Code Online (Sandbox Code Playgroud)