我试图创建一个程序,当你从下拉菜单中选择一个状态,它会在另一个下拉菜单,你可以从中选择显示的城市名单为状态。在你选择你的城市和州后,你输入一个地址,点击提交,它会在一个新的php文件上显示完整的地址。阿贾克斯,多重下拉菜单
例如,如果您从下拉菜单中选择新泽西州,在下拉菜单中它的左边应显示三个城市:纽瓦克,布卢姆菲尔德和爱迪生。
我现在的问题是我可以得到显示的状态,但是当选择状态时,它不会在第二个下拉菜单中为我提供该城市的选项列表。任何帮助表示赞赏,谢谢!
您可以在此link
select.php
<head>
<link rel="stylesheet" type="text/css" href="select_style.css">
<script type="text/javascript" src="js/jquery.js"></script>
<!DOCTYPE html>
<form action = "display.php">
<script type="text/javascript">
function fetch_select(val)
{
$.ajax({
type: 'get',
url: 'fetch.php',
data: {
get_option:val
},
success: function (response) {
document.getElementById("new_select").innerHTML=response;
}
});
}
</script>
</head>
<body>
<p id="heading">Address Generator</p>
<center>
<div id="select_box">
<select onchange="fetch_select(this.value);">
<option>Select state</option>
<?php
include ( "accounts.php" ) ;
($dbh = mysql_connect ($hostname, $username, $password))
or die ("Unable to connect to MySQL database");
print "Connected to MySQL<br>";
mysql_select_db($project);
$select=mysql_query("select state from zipcodes group by state");
while($row=mysql_fetch_array($select))
{
echo "<option value='".$row['state']."'>".$row['state']."</option>";
}
?>
</select>
<select id="new_select">
</select>
<div id='2'> </div>
<br><br>
<input type = text name="address">Address
<br><br>
<input type = submit>
</form>
fetch.php
<?php
include(accounts.php);
if(isset($_POST['get_option']))
{
($dbh = mysql_connect ($hostname, $username, $password))
or die ("Unable to connect to MySQL database");
print "Connected to MySQL<br>";
mysql_select_db($project);
$state = $_GET['get_option'];
$find=mysql_query("select city from zipcodes where state='$state'");
while($row=mysql_fetch_array($find))
{
echo "<option>".$row['city']."</option>";
}
exit;
}
?>
谢谢你,改变了它。 – Gillky
请投票批准;) –