[英]How to populate a drop down based on previous drop down selection SQL
我一直在遵循此解決方案1來創建一個下拉列表,該列表基於頁面上另一個下拉菜單中基於用戶先前選擇的更改。 但是我不確定在“期權”中需要做什么
謝謝
<?php
mysql_connect('localhost');
mysql_select_db("test");
$result = mysql_query("SELECT * FROM `contents` WHERE `parent` = 0");
echo "<select name='name'>";
while(($data = mysql_fetch_array($result)) !== false)
echo '<option value="', $data['id'],'">', $data['name'],'</option>'
?>
<select onchange="ajaxfunction(this.value)">
<!-- Options would have been initially populated here -->
</select>
<select id="sub">
</select>
<script type="text/javascript"> function ajaxfunction(parent)
{
$.ajax({
url: 'process.php?parent=' + parent;
success: function(data) {
$('#sub option').remove(); //// here sub is the id of second select box
$('#sub').append(data)
}
});
}
</script>
**<select onchange="ajaxfunction(this.value)">
**<!-- Options would have been initially populated here -->**
</select>**
<script type="text/javascript">
function ajaxfunction(parent)
{
$.ajax({
url: 'process.php?parent=' + parent;
success: function(data) {
$('#sub option').remove(); //// here sub is the id of second select box
$('#sub').append(data)
}
});
}
</script>
/// script section may be any where on your page
<select id="sub"> ////second select box
</select>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.