|
|
|
จะรับค่าข้อมูลเป็นตัวอักษรแทนการรับค่าเป็นตัวเลข ทำยังไงครับ |
|
|
|
|
|
|
|
DropDownList จะเก็บข้อมูลเป็นชื่อ จังหวัด แต่มันเก็บเป็นรหัสจังหวัด พอลองเปลี่ยน _ID เป็น _NAME มันก็ทำให้อำเภอไม่ขึ้น
Code (PHP)
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.ddlAmphur.length = 0
frmMain.ddlDistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_NAME ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mssql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["PROVINCE_ID"];?>;
strValue = "<?=$objResult["AMPHUR_ID"];?>";
strItem = "<?=$objResult["AMPHUR_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.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListDistrict(SelectValue)
{
frmMain.ddlDistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlDistrict.options[frmMain.ddlDistrict.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM district ORDER BY DISTRICT_NAME ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mssql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["AMPHUR_ID"];?>;
strValue = "<?=$objResult["DISTRICT_ID"];?>";
strItem = "<?=$objResult["DISTRICT_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.ddlDistrict.options[frmMain.ddlDistrict.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
</script>
Code (PHP)
จังหวัด
<select id="ddlProvince" name="select_hs_province" onChange = "ListAmphur(this.value)">
<option selected value="">---เลือก---</option>
<?
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_NAME ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["PROVINCE_ID"];?>"><?=$objResult["PROVINCE_NAME"];?></option>
<?
}
?>
</select>
อำเภอ
<select id="ddlAmphur" name="select_hs_amphur" style="width:120px" onChange = "ListDistrict(this.value)"></select>
</select>
ตำบล
<select id="ddlDistrict" name="select_hs_district" style="width:200px"></select>
</select>
Tag : PHP, Ms SQL Server 2008
|
|
|
|
|
|
Date :
2011-06-11 16:36:30 |
By :
MyZeus |
View :
785 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยอธิบายหน่อยคับ
|
|
|
|
|
Date :
2011-06-12 13:44:44 |
By :
MyZeus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|