|
|
|
การทำ list menu 2 ชั้น เลือกภาคแล้วแสดงจังหวัดในภาคนั้ๆแต่เลือกภาคแล้วจังหวัดไม่ขึ้น |
|
|
|
|
|
|
|
Code (PHP)
<? //require_once("Db_Connect.php");
require_once("include/config.php");
require_once("include/opendb.php"); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>Untitled Document</title>
<script language = "JavaScript">
//**** List pv (province) ***//
function ListPv(SelectValue)
{
frmMain.Pv.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.Pv.options[frmMain.Pv.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM province order by provinceid ";
$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["geoid"];?>;
strValue = "<?=$objResult["provinceid"];?>";
strItem = "<?=$objResult["provincename"];?>";
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.Pv.options[frmMain.Pv.length]= myOption
}
<?
}
?>
}
//**** List Pv (End) ***//
</script>
</head>
<body>
<form name="frmMain" action="" method="post">
Geo
<select id="geo" name="geo" onChange = "ListPv(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM geo ORDER BY geoid ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["geoid"];?>"><?=$objResult["geoname"];?></option>
<?
}
?>
</select>
Province
<select id="Pv" name="Pv" style="width:100px"></select>
</br>
</form>
</body>
</html>
จากโค้ด
การทำ list menu 2 ชั้น เลือกภาคแล้วแสดงจังหวัดในภาคนั้ๆแต่เลือกภาคแล้วจังหวัดไม่ขึ้น
ผิดตรงไหนครับ
Tag : PHP, MySQL, JavaScript
|
|
|
|
|
|
Date :
2012-03-22 11:47:00 |
By :
kung1451 |
View :
3236 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
View หน้า Source ของ IE มาให้หน่อยครับ
|
|
|
|
|
Date :
2012-03-22 11:51:20 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>Untitled Document</title>
<script language = "JavaScript">
//**** List pv (province) ***//
function ListPv(SelectValue)
{
frmMain.Pv.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.Pv.options[frmMain.Pv.length]= myOption
x = 1;
mySubList = new Array();
strGroup = 2;
strValue = "10";
strItem = "กรุงเทพ";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 2;
mySubList = new Array();
strGroup = 2;
strValue = "11";
strItem = "สมุทรปราการ";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 3;
mySubList = new Array();
strGroup = 2;
strValue = "12";
strItem = "นนทบุรี
";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 4;
mySubList = new Array();
strGroup = 2;
strValue = "13";
strItem = "ปทุมธานี
";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 5;
mySubList = new Array();
strGroup = 2;
strValue = "14";
strItem = "พระนครศรีอยุธยา
";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 6;
mySubList = new Array();
strGroup = 2;
strValue = "15";
strItem = "อ่างทอง
";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 7;
mySubList = new Array();
strGroup = 2;
strValue = "16";
strItem = "ลพบุรี
";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 8;
mySubList = new Array();
strGroup = 2;
strValue = "17";
strItem = "สิงห์บุรี
";
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.Pv.options[frmMain.Pv.length]= myOption
}
x = 9;
mySubList = new Array();
strGroup = 2;
strValue = "18";
strItem = "ชัยนาท
";
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.Pv.options[frmMain.Pv.length]= myOption
}
}
//**** List Pv (End) ***//
</script>
</head>
<body>
<form name="frmMain" action="" method="post">
Geo
<select id="geo" name="geo" onChange = "ListPv(this.value)">
<option selected value=""></option>
<option value="1">เหนือ</option>
<option value="2">กลาง</option>
<option value="3">ตะวันออกเฉียงเหนือ</option>
<option value="4">ตะวันออก</option>
<option value="5">ตะวันตก</option>
<option value="6">ใต้</option>
</select>
Province
<select id="Pv" name="Pv" style="width:100px"></select>
</br>
</form>
</body>
</html>
|
|
|
|
|
Date :
2012-03-22 13:26:59 |
By :
kung1451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สังเกตุว่าพวก
Code (PHP)
strItem = "นนทบุรี
";
ทำไมมันถึงตกครับ ลอง trim ดูครับ
Code (PHP)
strGroup = <?=$objResult["geoid"];?>;
strValue = "<?=trim($objResult["provinceid"]);?>";
strItem = "<?=trim($objResult["provincename"]);?>";
|
|
|
|
|
Date :
2012-03-22 13:45:07 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับ
ทำไมใส่ trim ด้วยครับอธิบายหน่อย
ขอบคุณครับ
|
|
|
|
|
Date :
2012-03-22 13:46:59 |
By :
kung1451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัด space พวกช่องว่างออกครับ มันอาจจะมี \n\t ครับ
|
|
|
|
|
Date :
2012-03-22 14:02:05 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ
|
|
|
|
|
Date :
2012-03-22 16:06:40 |
By :
kung1451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|