multi dropdown
รบกวนหน่อยครับ คือตอนนี้ปัญหาที่ยังแก้ไม่ตกคือ เมื่อเวลาจะ update จะทำยังไงให้สามารถ นำค่าที่มีอยู่มีใน db มาค้างในฟอร์มได้ รบกวนพี่ๆ ช่วยหน่อยครับ
//----------------------------------------------------------------------------------------------------
<td align="right">จังหวัด:</td>
<td><?
echo "<font id=province><select >\n";
echo "<option value='$prov_id'>============</option> \n" ;
echo "</select></font>\n";
?></td>
<td align="right">อำเภอ:</td>
<td><?
echo "<font id=amphur><select >\n";
echo "<option value='0'>=====none=====</option> \n" ;
echo "</select></font>\n";
?></td>
<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; //retuen value
}
}
};
req.open("GET", "state.php?data="+src+"&val="+val); //make connection
req.setRequestHeader("Content-Type", content="text/html; charset=Tis-620"); // set Header
req.send(null); //send value
}
window.onLoad=dochange('province', -1); // value in first dropdown
</script>
//end-----------------------------------------------------------------------------------------------------------------
//state.php
<?
//set IE read from page only not read from cache
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");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
//set database
$dbhost = "localhost";
$dbuser = "xxxx";
$dbpass = "xxxx";
$dbname = "xxxx";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
mysql_query("SET NAMES TIS620");
if ($data=='province') { // first dropdown
echo "<select name='province_id' onChange=\"dochange('amphur', this.value)\">\n";
echo "<option value='0'>====Province====</option>\n";
$result=mysql_db_query($dbname,"SELECT tblprovince.ProvinceID,tblprovince.ProvinceName FROM tblprovince ORDER BY tblprovince.ProvinceID ASC");
while(list($ProvinceID, $ProvinceName)=mysql_fetch_array($result)){
echo "<option value=\"$ProvinceID\">$ProvinceName</option> \n" ;
}
} else if ($data=='amphur') { // second dropdown
echo "<select name='district_id' >\n";
echo "<option value='0'>====Amphur====</option>\n";
$result=mysql_db_query($dbname,"SELECT tblamphur.AmphurCode,tblamphur.AmphurName,tblprovince.ProvinceName
FROM tblprovince INNER JOIN tblamphur ON tblprovince.ProvinceID = tblamphur.ProvinceCode
WHERE tblamphur.ProvinceCode = '$val' ");
while(list($AmphurCode, $AmphurName)=mysql_fetch_array($result)){
echo "<option value=\"$AmphurCode\" >$AmphurName</option> \n" ;
}
}
echo "</select>\n";
?>
มีใครช่วยได้บ้างมั๊ยครับ
หรือใครเคยทำวิธีไหน แนะนำกันได้
จะได้ลองทำดู
thx
Just use the search engine.
Find the words you want from the board.
แนะนำให้ลองค้นหาก่อนตั้งคำถามนะครับ...เพื่อที่จะได้ไม่เสียเวลาคอยคำตอบ