Skip to content

Instantly share code, notes, and snippets.

@magussiro
Forked from anonymous/test4.php
Created March 21, 2016 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magussiro/3de906edb4cfa05c69e1 to your computer and use it in GitHub Desktop.
Save magussiro/3de906edb4cfa05c69e1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language = "php">
session_start();
include("../admin/webconf.php");
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
<link rel="stylesheet" type="text/css" href="../css/test4_style.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
function county_select(val)
{
$.ajax({
type: 'post',
url: 'test4_action.php',
data: {
get_option:val
},
success: function (response) {
document.getElementById("new_select").innerHTML=response;
}
});
}
function city_select(val)
{
$.ajax({
type: 'post',
url: 'test4_action.php',
data: {
get_cityval:val
},
success: function (response) {
document.getElementById("kind_select").innerHTML=response;
}
});
}
function kind_select(val)
{
QQ = document.getElementById("new_select").value;
$.ajax({
type: 'post',
url: 'test4_action.php',
data: {
get_cityval:(QQ),
get_kindval:val
},
success: function (response) {
document.getElementById("school_select").innerHTML=response;
}
});
}
</script>
</head>
<body>
<p id="heading">Dynamic Select Option Menu Using Ajax and PHP</p>
<center>
<div id="select_box">
<select onchange="county_select(this.value);">
<?php
$select=mysql_query("SELECT * FROM county");
while($row=mysql_fetch_array($select))
{
echo "<option value=".$row['county_no'].">".$row['county_name']."</option>";
}
?>
</select>
<select id="new_select" onchange="city_select(this.value);">
</select>
<select id="kind_select" onchange="kind_select(this.value);">
</select>
<select id="school_select">
</select>
</div>
</center>
</body>
</html>
<?php
include("../admin/webconf.php");
if(isset($_POST['get_option']))
{
$state = $_POST['get_option'];
$find=mysql_query("SELECT * FROM city WHERE county_no ='$state'");
while($row=mysql_fetch_array($find))
{
echo "<option value=".$row['city_no'].">".$row['city_name']."</option>";
}
}
if( isset($_POST['get_cityval'] ))
{
$cityno = $_POST['get_cityval'];
$find=mysql_query("SELECT * FROM schoolkind ");
while($row=mysql_fetch_array($find))
{
echo "<option value=".$row['skind_no'].">".$row['skind_name']."</option>";
}
}
if( isset($_POST['get_kindval'] ))
{
$cityno = $_POST['get_cityval'];
$kindno = $_POST['get_kindval'];
$find=mysql_query("SELECT * FROM school where city_no = '$cityno' && school_kind ='$kindno'");
while($row=mysql_fetch_array($find))
{
echo "<option value=".$row['school_no'].">".$row['school_name']."</option>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment