|
|
|
ต้องการส่งค่า listbox 3 ชั้น ที่เก็บค่า id ในการ select จากค่า id listbox แรกที่ส่งค่ามา |
|
|
|
|
|
|
|
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("list_test");
@mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThaiCreate.Com ListMenu</title>
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListProvince(SelectValue)
{
frmMain.ddlProvince.length = 0
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('---------- เลือก ----------','')
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM total ORDER BY total_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["dep_id"];?>;
strValue = "<?=$objResult["ass_id"];?>";
strItem = "<?=$objResult["ass_id"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('---------- เลือก ----------','')
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM tb_series where dep_id=' ' ORDER BY ser_id ASC "; /*อยากรับค่า "<?=$objResult["dep_id"];?>" มาใส่หลังจาก where dep_id= */
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["ass_id"];?>;
strValue = "<?=$objResult["ser_name"];?>";
strItem = "<?=$objResult["com_name"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
</script>
</head>
<form name="frmMain" action="" method="post">
<p>เลือกภาค
<select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option selected value="">---------- เลือก ----------</option>
<?
$strSQL = "SELECT * FROM tb_dep ORDER BY dep_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["dep_id"];?>">
<?=$objResult["dep_name"];?>
</option>
<?
}
?>
</select>
</p>
<p>
เลือกจังหวัด
<select id="ddlProvince" name="ddlProvince" style="width:160px" onChange = "ListAmphur(this.value)">
</select>
</p>
<p>เลือกอำเภอ
<select name="ddlAmphur" id="ddlAmphur" style="width:160px">
</select>
</p>
</form>
</body>
</html>
<?
mysql_close($objConnect);
?>
|
|
|
|
|
Date :
2013-07-01 13:34:07 |
By :
sarayut.ton |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นี้โค้ดที่ใช้อยู่อะคับ
|
|
|
|
|
Date :
2013-07-01 13:34:34 |
By :
sarayut.ton |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไงดีนะ
|
|
|
|
|
Date :
2013-07-01 15:14:48 |
By :
sarayut.ton |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้ Search ดูครับ "Dependent Dropdown"
|
|
|
|
|
Date :
2013-07-01 19:35:55 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ เดียววันนี้ลองดูครับ
|
|
|
|
|
Date :
2013-07-02 09:07:20 |
By :
sarayut.ton |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-07-02 14:28:10 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไม่ได้เลยครับ วันนี้หาต่อ สู้ต่อไป
|
|
|
|
|
Date :
2013-07-03 12:12:35 |
By :
sarayut.ton |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|