Created
March 21, 2016 09:03
-
-
Save anonymous/ea2932031c42e6978790 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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