|
 |
|
ช่วยดูโค้ด Dependent ListMenu ด้วยค่ะไม่รู้ผิดตรงไหน |
|
 |
|
|
 |
 |
|
ไปก๊อบโค้ดจาก https://www.thaicreate.com/community/dependant-listmenu-dropdownlist.html นี่มาอ่ะคะ อิ อิ แล้วเอามาเปลี่ยนใช้กับฐานข้อมูลตัวเอง แต่ไม่รู้ว่าแก้ผิดตรงไหน listbox ชั้นที่ 3ไม่ขึ้นข้อมูลเลยคะ ช่วยดูให้หน่อยคะว่าแก้ผิดตรงไหน
Code (PHP)
<?php
include('../config.inc.php');
include('../function.php');
session_start();
connect_db($hostname,$user,$passwd);
$db=mysql_select_db($dbname);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>ThaiCreate.Com ListMenu</title>
<script language = "JavaScript">
//**** List subcate (Start) ***//
function Listsubcate(SelectValue)
{
frmMain.selectsubcate.length = 0
frmMain.selectProtype.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.selectsubcate.options[frmMain.selectsubcate.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM subcategory ORDER BY subcate_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["category_id"];?>;
strValue = "<?=$objResult["subcate_id"];?>";
strItem = "<?=$objResult["subcate_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.selectsubcate.options[frmMain.selectsubcate.length]= myOption
}
<?
}
?>
}
//**** List subcate (End) ***//
//**** List Protype (Start) ***//
function ListProtype(SelectValue)
{
frmMain.selectProtype.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.selectProtype.options[frmMain.selectProtype.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM product_type ORDER BY protype_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["subcate_id"];?>;
strValue = "<?=$objResult["protype_id"];?>";
strItem = "<?=$objResult["protype_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.selectProtype.options[frmMain.selectProtype.length]= myOption
}
<?
}
?>
}
//**** ListProtype (End) ***//
</script>
</head>
<form name="frmMain" action="" method="post">
หมวดสินค้า
<select id="selectCate" name="selectCate" onChange = "Listsubcate(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM category ORDER BY category_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["category_id"];?>"><?=$objResult["category_name"];?></option>
<?
}
?>
</select>
หมวดย่อยสินค้า
<select id="selectsubcate" name="selectsubcate" style="width:120px" onChange = "ListProtype(this.value)"></select>
ประเภทสินค้า
<select id="selectProtype" name="selectProtype" style="width:200px"></select>
</form>
</body>
</html>
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-07-18 09:48:25 |
By :
มือใหม่ |
View :
838 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 04
|