 |
อยากให้ list/menu เก็บค่าเป็นรหัส ตอนนี้ทำ list/menu 2 ชั้น (ใช้ ajax) คือให้เลือกแผนก list ที่ 1 แล้วกรอกคนที่อยู่แผนกที่เลือกใน list ที่ 2 |
|
 |
|
|
 |
 |
|
Code (PHP) dd.php
<?
$Department_id=$_GET['Department_id'];
require "../ajax-dd/config.php";// connection to database
$q=mysql_query("select * from tb_officer where Department_id='$Department_id'");
echo mysql_error();
/***********************/
$id = array();
$name = array();
while($nt=mysql_fetch_array($q)){
$id[] = "\"$nt[ID]\"";
$name[] = "\"$nt[Name]\"";
}
echo "new Array(".implode(",",$id).")|new Array(".implode(",",$name).")";
/***********************/
?>
Code (PHP)main.php
<html>
<body>
<script type="text/javascript">
function AjaxFunction(Department_id)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateck()
{
if(httpxml.readyState==4)
{
/*******************/
var t = httpxml.responseText.split("|");
var myarrayID=eval(t[0]);
var myarrayName=eval(t[1]);
/********************/
// Before adding new we must remove previously loaded elements
for(j=document.testform.subcat.options.length-1;j>=0;j--)
{
document.testform.subcat.remove(j);
}
/**************/
for (i=0;i<myarrayID.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarrayName[i];
optn.value = myarrayID[i];
document.testform.subcat.options.add(optn);
}
/************/
}
}
var url="../ajax-dd/dd.php";
url=url+"?Department_id="+Department_id;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
}
</script>
<form name="testform" method='POST' action='mainck.php'>
เลือกแผนก
<select name=cat onChange="AjaxFunction(this.value);">
<option value=''>Select One</option>
<?
require "../ajax-dd/config.php";// connection to database
$q=mysql_query("select * from tb_department");
while($n=mysql_fetch_array($q)){
echo "<option value=$n[Department_id]>$n[Department_name]</option>";
}
?>
</select>
เลือกผู้ใช้ <select name=subcat>
</select><input type=submit value=submit>
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2009-11-22 00:05:56 |
By :
lozomac |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สุดยอดดดดดดดดดดดดดดดดดด
ขอบคุณมากๆๆๆๆๆๆๆๆๆ นะจ๊ะ
|
 |
 |
 |
 |
Date :
2009-11-22 00:45:52 |
By :
patto |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เห็นโค้ดยาวๆแล้วตาละลาย คล้ายจะมึนตึบเด้อ... หุหุ 
|
 |
 |
 |
 |
Date :
2009-11-22 03:25:47 |
By :
melodyApinan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|