<select name="Faculty" id="Faculty" onChange = "Listdep(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM faculty ORDER BY ID_Fac ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["ID_Fac"];?>"><?=$objResult["Nm_Fac"];?></option>
<?
}
?>
</select>
</label>
<span class="selectRequiredMsg">กรุณาเลือกข้อมูล</span></span></span></td>
</tr>
<?
$host="localhost";
$user="root";
$password="123456";
$dbname="vehicles";
$connection=mysql_connect($host,$user,$password) or die("เชื่อมต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die("ไม่สามารถเลือกฐานข้อมูลได้");
$cs1 = "SET character_set_results=tis620";
mysql_query($cs1) or die('Error query: ' . mysql_error());
$cs2 = "SET character_set_client = tis620";
mysql_query($cs2) or die('Error query: ' . mysql_error());
$cs3 = "SET character_set_connection = tis620";
mysql_query($cs3) or die('Error query: ' . mysql_error());
?>
<script language = "JavaScript">
//**** List Province (Start) ***//
function Listdep(SelectValue)
{
frmMain.Department.length = 0
frmMain.Department.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.Department.options[frmMain.Department.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM department ORDER BY ID_Dep 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["ID_Fac"];?>;
strValue = "<?=$objResult["ID_Dep"];?>";
strItem = "<?=$objResult["Dep_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.Department.options[frmMain.Department.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//