|
|
|
ถามเรื่องการใช้ onchange การกำหนดค่าเริ่มต้นของ dropdown menu ครับ |
|
|
|
|
|
|
|
พอเราเลือก dropdownlist อันที่ 1 แล้ว
dropdownlist อันที่ 2 ก็จะเกิดการเปลี่ยนแปลง
อันนี้ทำได้แล้วครับ
[font=Verdana]แต่[/font]คราวนี้ช่องแรกของ dropdownlist อันที่ 2 จะกลายเป็นว่างอ่ะครับ ไม่มีอะไรเลย 1 ช่อง
ต้องการให้แสดงคำว่า "กรุณาเลือกสำนักงานย่อย" และมีค่าเป็น 0 ครับ
อันนี้โค้ดครับ
Code (PHP)
<?php
session_start();
include("connect_db.php");
connect_db();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListSubOffice(SelectValue)
{
form1.s_office.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
form1.s_office.options[form1.s_office.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM s_office ORDER BY s_office_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["office_id"];?>;
strValue = "<?=$objResult["s_office_id"];?>";
strItem = "<?=$objResult["s_office_n"];?>";
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])
form1.s_office.options[form1.s_office.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
</script>
</head>
<body>
<form name="form1" action="test.php" method="post">
Office
<select id="office" name="office" onChange = "ListSubOffice(this.value)">
<option selected value="0">กรุณาเลือกหน่วยงาน</option>
<?
$strSQL = "SELECT * FROM office ORDER BY office_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["office_id"];?>"><?=$objResult["office_n"];?></option>
<?
}
?>
</select>
Sub Office
<select id="s_office" name="s_office" style="width:120px"></select>
</form>
</body>
</html>
กระทู้เดิมไม่มีคนตอบเลยอ่ะครับ
https://www.thaicreate.com/php/forum/064512.html
Tag : PHP, MySQL, HTML/CSS, JavaScript, CakePHP
|
|
|
|
|
|
Date :
2011-08-10 18:41:06 |
By :
ixoxi |
View :
1314 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้แล้วครับ ขอบคุณครับ
|
|
|
|
|
Date :
2011-08-10 19:06:13 |
By :
ixoxi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|