|
 |
|
สืบเนื่องจาก การใช้ Dependant ListMenu คือว่าจาก โค้ด Dependant ListMenu ครับ ดีผมลองเอาโค้ดดังกล่าว ไปทำการแก้ไขนิดหน่อย |
|
 |
|
|
 |
 |
|
คือว่าจาก โค้ด Dependant ListMenu ครับ พอดีผมลองเอาโค้ดดังกล่าว ไปทำการแก้ไขนิดหน่อย โดยผมเพิ่มหมู่บ้านเข้าไปด้วย ครับ ปัญหาที่ผมติดตอนนี้คือ เมื่อทำการเลือก จังหวัด ---> อำเภอ ----> ตำบล จนถึง หมู่บ้าน ได้แล้วผมต้องการให้ หมู่ที่แสดงใน textbox โดยผมจะถึงหมู่จาก ฐานข้อมูลของหมู่บ้าน ไม่รู้ต้องแก้ยังไงครับ ขอบคุณ สำหรับ โค้ด ดีๆๆ ครับ
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost","root","065863786") or die("Error Connect to Database");
$objDB = mysql_select_db("supply");
@mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThaiCreate.Com ListMenu</title>
<script language = "JavaScript">
//**** List อำเภอ (Start) ***//
function ListProvince(SelectValue)
{
frmMain.district.length = 0
frmMain.subdistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.district.options[frmMain.district.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM amper ORDER BY amper_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["prov_id"];?>;
strValue = "<?=$objResult["amper_id"];?>";
strItem = "<?=$objResult["amper"];?>";
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.district.options[frmMain.district.length]= myOption
}
<?
}
?>
}
//**** List อำเภอ (End) ***//
//**** List ตำบล (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.subdistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.subdistrict.options[frmMain.subdistrict.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM tumbon ORDER BY tumbon_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["amper_id"];?>;
strValue = "<?=$objResult["tumbon_id"];?>";
strItem = "<?=$objResult["tumbon"];?>";
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.subdistrict.options[frmMain.subdistrict.length]= myOption
}
<?
}
?>
}
//**** List ตำบล (End) ***//
//**** List หมู่บ้าน (Start) ***//
function ListTumbon(SelectValue)
{
frmMain.ban.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ban.options[frmMain.ban.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM mooban ORDER BY mooban_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["tumbon_id"];?>;
strValue = "<?=$objResult["mooban_id"];?>";
strItem = "<?=$objResult["mooban"];?>";
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.ban.options[frmMain.ban.length]= myOption
}
<?
}
?>
}
//**** List หมู่บ้าน (End) ***//
//**** List หมู่บ้านที่ (Start) ***//
function Listmoo(SelectValue)
{
frmMain.m.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.m.options[frmMain.m.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM mooban ORDER BY mooban_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["tumbon_id"];?>;
strValue = "<?=$objResult["no_mo"];?>";
strItem = "<?=$objResult["no_mo"];?>";
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.m.options[frmMain.m.length]= myOption
}
<?
}
?>
}
//**** List หมู่บ้าน (End) ***//
</script>
</head>
<form name="frmMain" action="" method="post">
<input type="textbox" name="text">
Province
<select id="ddlGeo" name="province" onChange = "ListProvince(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM province ORDER BY prov_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["prov_id"];?>"><?=$objResult["prov"];?></option>
<?
}
?>
</select>
Amphur
<select id="district" name="district" style="width:120px" onChange = "ListAmphur(this.value)"></select>
Tumbon
<select id="subdistrict" name="subdistrict" style="width:200px" onChange = "ListTumbon(this.value)"></select>
Mooban
<!-- <select id="ban" name="ban" style="width:200px" onChange = "ListMoo(this.value)+frmMain.m.value=this.value" ></select>-->
<select id="ban" name="ban" style="width:200px" onChange = "frmMain.m.value=this.value" ></select>
number_moo
<input id ="m" name="m" type="text">
<input type="submit" name="submit" value="ตกลง">
</form>
</body>
</html>
<?
mysql_close($objConnect);
echo "จังหวัด $province<br>";
echo "อำเภอ $district<br>";
echo "ตำบล $subdistrict<br>";
echo "หมู่บ้าน$ban<br>";
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-03-02 22:44:31 |
By :
drakvender |
View :
1059 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ สำหรับคำแนะนำครับ
แต่ผมติดอยู่นิดเดียวอ่ะครับ ตรงที่จะนำ หมู่ที่ นำมาใส่ใน
Code (PHP)
number_moo
<input id ="m" name="m" type="text">
โดยเมื่อทำการเลือกตรงนี้
<select id="ban" name="ban" style="width:200px" onChange = "ListMoo(this.value)" ></select>
จะไปเรียกใช้ Java Script แล้ว ส่งกลับมาที่
number_moo
<input id ="m" name="m" type="text">
ผมจะต้องเขียนยังไงครับขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2010-03-03 07:49:00 |
By :
drakvender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยน listbox มารับค่าแทน texbox ที่ใช้ดูครับ
|
 |
 |
 |
 |
Date :
2010-03-03 10:40:36 |
By :
ความรู้เท่าหางอึ่ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นอกจากเปลี่ยน จาก textbox มาใช้ list box ยังมีวิธีไหน อีกครับ
|
 |
 |
 |
 |
Date :
2010-03-03 16:12:19 |
By :
drakvender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มึนเลย ติดมาหลายวันละ อิอิ สู้สู้
|
 |
 |
 |
 |
Date :
2010-03-04 10:47:45 |
By :
drakvender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|