|
|
|
รบกวนช่วยดูโค้ดให้หน่อยครับ dependent dropdown list ค่าไม่เข้าครับ |
|
|
|
|
|
|
|
รบกวนหน่อยครับ(มือใหม่ครับ)
พอดีผมมีปัญหาเรื่องการทำ dependent dropdown list ซึ่งผมได้ดูตัวอย่างไปจากทาง thaicreate แล้ว
ผมต้องการให้ Division > Department > Section ขึ้นเป็น Dependent กัน
แต่โค้ดตอนนี้ที่แสดง มันขึ้นที่ เฉพาะ Division กับ Department ส่วน Section ไม่ขึ้นครับ
ผมทำการ Debug ค่า onchange(this.value) ดู ปรากฎว่าค่ามันไม่เข้าใน ListSection(this.value) ครับ
รบกวนพี่ๆช่วยชี้แนะ หน่อยครับ ขอบคุณครับ
Code (PHP)
<section id="main" class="column">
<h4 class="alert_info">Welcome to Maintain Employee Form</h4>
<script language="javascript">
function ListDepartment(SelectValue)
{
$bin = SelectValue
alert($bin);
frmMain.ddlDep.length = 0
frmMain.ddlSec.length = 0
//*** Insert null Default Value ***//
//var myOption = new Option('','')
var myOption = new Option('')
frmMain.ddlDep.options[frmMain.ddlDep.length]= myOption
<?php
$strSQL = "SELECT * FROM Department ORDER BY division_id,department_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
str1 = <?php echo $objResult["division_id"];?>;
str2 = "<?php echo $objResult["department_id"];?> - <?php echo $objResult["department_name"];?>";
mySubList[x,0] = str2;
mySubList[x,1] = str1;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0])
frmMain.ddlDep.options[frmMain.ddlDep.length]= myOption
frmMain.ddlDep.value[frmMain.ddlDep.length]= myOption
}
<?php
}
?>
}
function ListSection(SelectValue)
{
$bin2 = SelectValue
alert($bin2);
frmMain.ddlSec.length = 0
//*** Insert null Default Value ***//
//var myOption = new Option('','')
var myOption = new Option('')
frmMain.ddlSec.options[frmMain.ddlSec.length]= myOption
<?php
$strSQL = "SELECT * FROM section ORDER BY department_id,section_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
str1 = <?php echo $objResult["department_id"];?>;
str2 = "<?php echo $objResult["section_id"];?> - <?php echo $objResult["section_name"];?>";
mySubList[x,0] = str2;
mySubList[x,1] = str1;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0])
frmMain.ddlSec.options[frmMain.ddlSec.length]= myOption
}
<?php
}
?>
}
function ListEditDepartment(SelectValue)
{
frmMain.ddlDep2.length = 0
//*** Insert null Default Value ***//
//var myOption = new Option('','')
var myOption = new Option('')
frmMain.ddlDep2.options[frmMain.ddlDep2.length]= myOption
<?php
$strSQL = "SELECT * FROM Department ORDER BY division_id,department_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
str1 = <?php echo $objResult["division_id"];?>;
str2 = "<?php echo $objResult["department_id"];?> - <?php echo $objResult["department_name"];?>";
mySubList[x,0] = str2;
mySubList[x,1] = str1;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0])
frmMain.ddlDep2.options[frmMain.ddlDep2.length]= myOption
}
<?php
}
?>
}
</script>
<article class="module width_full">
<header><h3>Add Employee</h3></header>
<div class="module_content">
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<table width="100%" border="0" cellpadding="5">
<tr>
<td>Division Name :</td>
<td>
<div align="left">
<select id="ddlDiv" name="txtAddDivisionID" style="width:300px" onChange = "ListDepartment(this.value)">
<option selected value=""></option>
<?php
$strSQL = "SELECT * FROM division ORDER BY division_id ASC ";
$objQuery_div = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery_div))
{
?>
<option value="<?php echo $objResult["division_id"];?>"><?php echo $objResult["division_id"];?> - <?php echo $objResult["division_name"];?></option>
<?php
}
?>
</select>
</div>
</td>
</tr>
<tr>
<td>Department Name :</td>
<td>
<div align="left">
<select id="ddlDep" name="txtAddDepartmentID" style="width:300px" onChange = "ListSection(this.value)"></select>
</div>
</td>
</tr>
<tr>
<td>Section Name :</td>
<td>
<div align="left">
<select id="ddlSec" name="txtAddSectionID" style="width:300px"></select>
</div>
</td>
</tr>
<tr>
<td>Employee ID :</td>
<td><input type="text" name="txtAddEmployeeID" size="6"></td>
</tr>
<tr>
<td>Employee Name :</td>
<td><input type="text" name="txtAddEmployeeName" size="50"></td>
</tr>
<tr>
<td>Employee Nickname :</td>
<td><input type="text" name="txtAddEmployeeNickName" size="10"></td>
</tr>
<tr>
<td>Table phone :</td>
<td><input type="text" name="txtAddTablePhone" size="3"></td>
</tr>
<tr>
<td>Mobile Phone :</td>
<td><input type="text" name="txtAddMobilePhone" size="12"></td>
</tr>
<tr>
<td>Internal Mail :</td>
<td><input type="text" name="txtAddInternalMail" size="50"></td>
</tr>
<tr>
<td>External Mail :</td>
<td><input type="text" name="txtAddExternalMail" size="50"></td>
</tr>
<tr>
<td>Position :</td>
<td><input type="text" name="txtAddPosition" size="30"></td>
</tr>
<tr>
<td>Status :</td>
<td><input type="text" name="txtAddStatus" size="5"></td>
</tr>
<tr>
<td>Activate :</td>
<!--<td><input type="text" name="txtAddActivate" size="1"></td>-->
<td>
<div align="left">
<select id="ddlAct" name="txtAddActivate">
<option value="1">Yes</option>
<option value="2">No</option>
</select>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
<input type="reset" value="Clear">
</div></td>
</tr>
</table>
</div>
</article>
<article class="module width_full">
<header><h3>Section</h3></header>
<div class="module_content">
<?php
$strSQL = "SELECT sec.division_id, di.division_name, sec.department_id, dep.department_name, sec.section_id, sec.section_name
from department as dep, division as di, section as sec
where sec.division_id = dep.division_id
and sec.department_id = dep.department_id
and dep.division_id = di.division_id
order by sec.division_id, dep.department_id, sec.section_id";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<input type="hidden" name="hdnCmd" value="">
<table width="100%" border="1" cellpadding="5">
<tr>
<th> <div align="center">Division Name </div></th>
<th> <div align="center">Department Name </div></th>
<th> <div align="center">Section ID</div></th>
<th> <div align="center">Section Name</div></th>
<th> <div align="center">Edit</div></th>
<th> <div align="center">Delete</div></th>
</tr>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?php
if($objResult["division_id"] == $_GET["DivID"] and $objResult["department_id"] == $_GET["DepID"]
and $objResult["section_id"] == $_GET["SecID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td>
<div align="center">
<select id="ddlDiv" name="txtEditDivisionID" style="width:80px" onChange = "ListEditDepartment(this.value)">
<option selected value=""></option>
<?php
$strSQL = "SELECT * FROM division ORDER BY division_id ASC ";
$objQuery_div1 = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult1 = mysql_fetch_array($objQuery_div1))
{
if($objResult["division_id"]==$objResult1["division_id"])
{
?>
<option value="<?php echo $objResult1["division_id"];?>" selected><?php echo $objResult1["division_id"];?> - <?php echo $objResult1["division_name"];?></option>
<?php
}
else
{ ?>
<option value="<?php echo $objResult1["division_id"];?>"><?php echo $objResult1["division_id"];?> - <?php echo $objResult1["division_name"];?></option>
<? }
}
?>
</select>
<input type="hidden" name="hdnEditDivisionID" size="2" value="<?php echo $objResult["division_id"];?> - <?php echo $objResult["division_name"];?>">
</div>
</td>
<td>
<div align="left">
<select id="ddlDep2" name="txtEditDepartmentID" style="width:300px" >
<option value="<?php echo $objResult["department_id"];?> - <?php echo $objResult["department_name"];?>" selected=true><?php echo $objResult["department_id"];?> - <?php echo $objResult["department_name"];?></option></select>
<input type="hidden" name="hdnEditDepartmentID" size="2" value="<?php echo $objResult["department_id"];?> - <?php echo $objResult["department_name"];?>"></td>
</div>
<td><input type="text" name="txtEditSectionID" size="2" value="<?php echo $objResult["section_id"];?>">
<input type="hidden" name="hdnEditSectionID" size="2" value="<?php echo $objResult["section_id"];?>"></td>
<td><input type="text" name="txtEditSectionName" size="50" value="<?php echo $objResult["section_name"];?>"></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?php echo $_SERVER["PHP_SELF"];?>';">
</div></td>
</tr>
<?php
}
else
{
?>
<tr>
<td><div align="left"><?php echo $objResult["division_id"];?> - <?php echo $objResult["division_name"];?></div></td>
<td><div align="center"><?php echo $objResult["department_id"];?> - <?php echo $objResult["department_name"];?></div></td>
<td><div align="center"><?php echo $objResult["section_id"];?></div></td>
<td><div align="left"><?php echo $objResult["section_name"];?></div></td>
<td align="center"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&DivID=<?php echo $objResult["division_id"];?>&DepID=<?php echo $objResult["department_id"];?>&SecID=<?php echo $objResult["section_id"];?>"><img src="images/icn_edit.png" border="0"/></a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&DivID=<?php echo $objResult["division_id"];?>&DepID=<?php echo $objResult["department_id"];?>&SecID=<?php echo $objResult["section_id"];?>';}"><img src="images/icn_trash.png" border="0"/></a></td>
</tr>
<?php
}
}?>
</table>
</form>
<div class="clear"></div>
</div>
</article><!-- end of stats article -->
</section>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Windows
|
ประวัติการแก้ไข 2015-03-11 13:27:50
|
|
|
|
|
Date :
2015-03-11 10:16:46 |
By :
chaserake |
View :
679 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132. <select id="ddlDep" name="txtAddDepartmentID" style="width:300px" onChange = "ListSection(this.value)" ></select>
> หายไปตัวนึงหรือเปล่า
|
|
|
|
|
Date :
2015-03-11 12:19:11 |
By :
ไม่ทราบแหล่งที่มา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับพี่ สงสัยตอนดีบักผมลืมเครื่องหมายไป แต่ใส่แล้วค่ายังไม่ขึ้นมาเลยครับ
|
|
|
|
|
Date :
2015-03-11 13:11:26 |
By :
chaserake |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|