|
 |
|
คือพอเวลารันแล้ว กดปุ่ม listbox ของจังหวัดแล้วไม่มีข้อมูล ลองดูโค้ดให้หน่อยน่ะค่ะ |
|
 |
|
|
 |
 |
|
ไฟล์ test.html
Code (PHP)
<html>
<head>
<title>:: ทำ AJAX ของ Drop Down Menu ที่ไว้เลือกจังหวัด อำเภอ ตำบล ของไทย ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText; //รับค่ากลับมา
}
}
};
req.open("GET", "locale.php?data="+src+"&val="+val); //สร้าง connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
req.send(null); //ส่งค่า
}
window.onLoad=dochange('province', -1);
</script>
</head>
<body>
<form name="sel" method="post" action="send_data.php">
จังหวัด : <font id="province"><select><option value="0">=========================</option></select></font>
อำเภอ : <font id="amphur"><select><option value='0'>=========================</option></select></font>
ตำบล : <font id="district"><select><option value='0'>=========================</option></select></font>
<br><br><input type="submit" name="Submit" value="ส่งข้อมูล"> <INPUT type="reset" value="ยกเลิก">
</form>
<br>
</body>
</html>
ไฟล์ locale.php
Code (PHP)
<?php
header("content-type: text/html; charset=utf-8");
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
include("connect.php");
$data = $_GET['data'];
$val = $_GET['val'];
if ($data=='province') {
echo "<select name='province' onChange=\"dochange('amphur', this.value)\">\n";
echo "<option value='0'>==== เลือกจังหวัด ====</option>\n";
$SQL = "select * from province order by PROVINCE_NAME";
$stmt=oci_parse($objConnect,$SQL);
oci_execute($stmt,OCI_DEFAULT);
while($row = oci_fetch_array($stmt,OCI_BOTH)){
echo "<option value=\"$row[PROVINCE_ID]\" >$row[PROVINCE_NAME]</option> \n" ;
}
} else if ($data=='amphur') {
echo "<select name='amphur' onChange=\"dochange('district', this.value)\">\n";
echo "<option value='0'>========= เลือกอำเภอ =========</option>\n";
$SQL = "SELECT * FROM amphur WHERE \"PROVINCE_ID\"= '$val' ORDER BY AMPHUR_NAME";
$stmt=oci_parse($objConnect,$SQL);
oci_execute($stmt,OCI_DEFAULT);
while($row = oci_fetch_array($stmt,OCI_BOTH)){
echo "<option value=\"$row[AMPHUR_ID]\" >$row[AMPHUR_NAME]</option> \n" ;
}
} else if ($data=='district') {
echo "<select name='district'>\n";
echo "<option value='0'>========= เลือกตำบล =========</option>\n";
$SQL = "SELECT * FROM district WHERE \"AMPHUR_ID\"= '$val' ORDER BY DISTRICT_NAME";
$stmt=oci_parse($objConnect,$SQL);
oci_execute($stmt,OCI_DEFAULT);
while($row = oci_fetch_array($stmt,OCI_BOTH)){
echo "<option value=\"$row[DISTRICT_ID]\" >$row[DISTRICT_NAME]</option> \n" ;
}
}
echo "</select>\n";
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-12-17 18:36:54 |
By :
eii |
View :
1073 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ ตอนรันกับ mysql รันได้ ก้อเลย import ตัวฐานไปยัง oracle แล้วนำโค้ดเดิมมารัน เปลี่ยนโค้ด นิดหน่อยค่ะ แต่กลับเลือกจังหวัดไม่ได้
ช่วยดูโค้ดให้หน่อยค่ะ
|
 |
 |
 |
 |
Date :
2011-12-17 22:46:32 |
By :
eii-mian |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะเป็น ตัวแปร ผิดอยู่นะคะ ดูดีๆนะคะ คิดว่าผิดอยู่
|
 |
 |
 |
 |
Date :
2011-12-17 22:53:54 |
By :
PG |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$SQL = "SELECT * FROM district WHERE \"AMPHUR_ID\"= '$val' ORDER BY \"DISTRICT_NAME\"";
|
 |
 |
 |
 |
Date :
2011-12-19 15:13:02 |
By :
onedan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|