|
|
|
อยากทราบว่าจะทำยังไงให้มันกลับมารับค่าตัวหนังสือได้อีกครั้งครับ |
|
|
|
|
|
|
|
ขอดู code หน่อยได้ไหม ครับ ผมว่าในส่วนของ ตัว ค่า values ที่ส่ง มาอะ ครับ ถ้าเป็นไปได้ก็น่าจะส่งค่าแบบตัว อักษรมานะครับ
|
|
|
|
|
Date :
2011-03-03 18:00:02 |
By :
SOUL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อันนี้เป็นส่วนของจาวาสคริป ของไทยครีเอท ยังไม่ได้แก้ไขใดๆ เพราะว่ามันดึงมาจากฐานข้อมูล
Code (PHP)
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListProvince(SelectValue)
{
form.Province.length = 0
form.Aumpur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('กรุณาเลือกจังหวัด','')
form.Province.options[form.Province.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_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["GEO_ID"];?>;
strValue = "<?=$objResult["PROVINCE_ID"];?>";
strItem = "<?=$objResult["PROVINCE_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])
form.Province.options[form.Province.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListAmphur(SelectValue)
{
form.Aumpur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('กรุณาเลือกเขต/อำเภอ','')
form.Aumpur.options[form.Aumpur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_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["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])
form.Aumpur.options[form.Aumpur.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
</script>
ส่วนนี้เป็นส่วนฟอร์มรับค่า ธรรมดาๆๆ ตัดมาบางส่วนนะครับ
Code (PHP)
[php]<th scope="col" align="left" class="style1">ภาค<br /> <select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option selected value="">กรุณาเลือกภูมิภาค</option>
<?
$strSQL = "SELECT * FROM geography ORDER BY GEO_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["GEO_ID"];?>"><?=$objResult["GEO_NAME"];?></option>
<?
}
?>
</select>
</th>
<th scope="col" align="left" class="style1"> </th>
</tr>
<tr>
<th scope="col"> </th>
<th scope="col" align="left" class="style1">จังหวัด <span class="style6">*</span><br /><select id="Province" name="Province" style="width:120px" onChange = "ListAmphur(this.value)"></select>
</th>
<th scope="col" align="left" class="style1">เขต/อำเภอ <span class="style6">*</span><br /><select id="Aupur" name="Aumpur" style="width:200px"></select>
</th>
[/php]
|
|
|
|
|
Date :
2011-03-06 09:45:56 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<!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 type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#select').change(function(){
alert($('#select :selected').text());
// javascript
var w = document.getElementById('select').selectedIndex;
var selected_text = document.getElementById('select').options[w].text;
alert(selected_text);
});
});
</script>
</head>
<body>
<p>
<select name="select" id="select">
<option value="1">อุบล</option>
<option value="2">อุดร</option>
<option value="3">ยโสธร</option>
<option value="4">อำนาจ</option>
</select>
</p>
</body>
</html>
ไม่รู้ว่าผมเข้าใจคุณอ้นหรือเปล่าหน่ะครับ
คือจะเอา ชื่อจังหวัดของไอดี ที่เลือก เช่น ไอดี 2 คือ จังหวัดสมุทรปราการ อย่างนี้หรือเปล่าครับ
ถ้าเข้าใจผิด ก็ขออำภัย หน่ะครับ
|
|
|
|
|
Date :
2011-03-06 12:32:07 |
By :
ไวยวิทย์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เข้าใจถูกต้องครับ แต่ตัวโค๊ดควรจะต้องแก้จากของเดิมครับ
|
|
|
|
|
Date :
2011-03-06 16:53:23 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<!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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> ทดลองเลือกภาค จังหวัด อำเภอ และ ตำบล จ้า</title>
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("geo");
@mysql_query("SET NAMES UTF8");
?>
<script language = "JavaScript" type="text/javascript" >
//**** List Province (Start) ***//
function ListProvince(SelectValue)
{
document.frmMain.ddlProvince.length = 0
//document.frmMain.ddlAmphur.length = 0
//document.frmMain.ddldistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('--เลือกจังหวัด--','0')
document.frmMain.ddlProvince.options[document.frmMain.ddlProvince.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM province ORDER BY province_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["geo_id"];?>;
strValue = "<?=$objResult["province_id"];?>";
strItem = "<?=$objResult["province_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])
document.frmMain.ddlProvince.options[document.frmMain.ddlProvince.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListAmphur(SelectValue)
{
document.frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('--เลือกอำเภอ--','0')
document.frmMain.ddlAmphur.options[document.frmMain.ddlAmphur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY amphur_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["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])
document.frmMain.ddlAmphur.options[document.frmMain.ddlAmphur.length]= myOption
}
<?
}
?>
var w = document.getElementById('ddlProvince').selectedIndex;
var province_text = document.getElementById('ddlProvince').options[w].text;
document.getElementById('province_text').value = province_text;
}
//**** List Amphur (End) ***//
//**** List district (Start) ***//
function Listdistrict(SelectValue)
{
document.frmMain.ddldistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('--เลือกตำบล--','0')
document.frmMain.ddldistrict.options[document.frmMain.ddldistrict.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM district ORDER BY district_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["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])
document.frmMain.ddldistrict.options[document.frmMain.ddldistrict.length]= myOption
}
<?
}
?>
var w = document.getElementById('ddlAmphur').selectedIndex;
var amphur_text = document.getElementById('ddlAmphur').options[w].text;
document.getElementById('amphur_text').value = amphur_text;
}
//**** List district (End) ***//
function district_list()
{
var w = document.getElementById('ddldistrict').selectedIndex;
var district_text = document.getElementById('ddldistrict').options[w].text;
document.getElementById('district_text').value = district_text;
}
</script>
</head>
<form name="frmMain" action="test.php" method="post">
ภาค :
<select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option select value="0">-- เลือกภาค --</option>
<?
$strSQL = "SELECT * FROM geography ORDER BY geo_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["geo_id"];?>"><?=$objResult["geo_name"];?></option>
<?
}
?>
</select>
จังหวัด :
<select id="ddlProvince" name="ddlProvince" style="width:120px" onChange = "ListAmphur(this.value)">
<option value="0">-- เลือกจังหวัด --</option>
</select>
อำเภอ :
<select id="ddlAmphur" name="ddlAmphur" style="width:200px" onchange = "Listdistrict(this.value)">
<option value="0">-- เลือกอำเภอ --</option>
</select>
ตำบล :
<select id="ddldistrict" name="ddldistrict" style="width:200px" onchange="district_list()">
<option value="0">-- เลือกตำบล --</option>
</select>
<input name="province_text" id="province_text" type="hidden" />
<input name="amphur_text" id="amphur_text" type="hidden" />
<input name="district_text" id="district_text" type="hidden" />
<input type="submit" name="button" id="button" value="Submit" />
</form>
</body>
</html>
<?
mysql_close($objConnect);
?>
test.php
Code (PHP)
<?php
echo $_POST['ddlGeo']." : ";
echo "<BR>";
echo $_POST['ddlProvince']. " : ".$_POST['province_text'];
echo "<BR>";
echo $_POST['ddlAmphur']. " : ".$_POST['amphur_text'];
echo "<BR>";
echo $_POST['ddldistrict']. " : ".$_POST['district_text'];
?>
|
|
|
|
|
Date :
2011-03-07 08:42:50 |
By :
ไวยวิทย์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|