|
|
|
Dependant listmenu javascript + เขียนเอามาจากฐานข้อมูลยังไงครับ |
|
|
|
|
|
|
|
Dependant listmenu javascript + เขียนเอามาจากฐานข้อมูลยังไงครับ
ตาม code เขียนข้อมูลไปเลย แต่ถ้าดึงข้อมูลมาจากฐานข้อมูลต้องทำยังไงครับ
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" />
<script language="javascript" type="text/javascript">
function dropdownlist(listindex)
{
document.formname.subcategory.options.length = 0;
switch (listindex)
{
case "Home Ware" :
document.formname.subcategory.options[0]=new Option("Select Sub-Category","");
document.formname.subcategory.options[1]=new Option("Air-Conditioners/Coolers","Air-Conditioners/Coolers");
document.formname.subcategory.options[2]=new Option("Audio/Video","Audio/Video");
document.formname.subcategory.options[3]=new Option("Beddings","Beddings");
document.formname.subcategory.options[4]=new Option("Camera","Camera");
document.formname.subcategory.options[5]=new Option("Cell Phones","Cell Phones");
break;
case "Education" :
document.formname.subcategory.options[0]=new Option("Select Sub-Category","");
document.formname.subcategory.options[1]=new Option("Colleges","Colleges");
document.formname.subcategory.options[2]=new Option("Institutes","Institutes");
document.formname.subcategory.options[3]=new Option("Schools","Schools");
document.formname.subcategory.options[4]=new Option("Tuitions","Tuitions");
document.formname.subcategory.options[5]=new Option("Universities","Universities");
break;
case "Books" :
document.formname.subcategory.options[0]=new Option("Select Sub-Category","");
document.formname.subcategory.options[1]=new Option("College Books","College Books");
document.formname.subcategory.options[2]=new Option("Engineering","Engineering");
document.formname.subcategory.options[3]=new Option("Magazines","Magazines");
document.formname.subcategory.options[4]=new Option("Medicine","Medicine");
document.formname.subcategory.options[5]=new Option("References","References");
break;
}
return true;
}
</script>
</head>
<title>Dynamic Drop Down List</title>
<body>
<form id="formname" name="formname" method="post" action="submitform.asp" >
<table width="50%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="41%" align="right" valign="middle">Category :</td>
<td width="59%" align="left" valign="middle"><select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
<option value="">Select Category</option>
<option value="Home Ware">Home Ware</option>
<option value="Education">Education</option>
<option value="Books">Books</option>
</select></td>
</tr>
<tr>
<td align="right" valign="middle">Sub Category :
</td>
<td align="left" valign="middle"><script type="text/javascript" language="JavaScript">
document.write('<select name="subcategory"><option value="">Select Sub-Category</option></select>')
</script>
<noscript><select name="subcategory" id="subcategory" >
<option value="">Select Sub-Category</option>
</select>
</noscript></td>
</tr>
</table>
</form>
</body>
</html>
Tag : PHP, HTML/CSS, JavaScript
|
|
|
|
|
|
Date :
2011-04-11 12:13:24 |
By :
the_cop |
View :
3736 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นั่งทำมั่วๆ ได้แล้วคับ อิอิ
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" />
<? include ("conn.php");?>
<script language="javascript" type="text/javascript">
function dropdownlist(listindex)
{
document.formname.subcategory.options.length = 0;
switch (listindex)
{
<?
$sql_="select * from faculty";
$re_=mysql_query($sql_);
while ($data_=mysql_fetch_array($re_)){
?>
case "<?=$data_[faculty_id]?>" :
<?
$sql_1="select * from department where faculty_id=$data_[faculty_id]";
$re_1=mysql_query($sql_1);
$i=0;
while ($data_1=mysql_fetch_array($re_1)){
?>
document.formname.subcategory.options[<?=$i?>]=new Option("<?=$data_1[depart_name]?>","");
<? $i++;
}?>
break;
<? }?>
}
return true;
}
</script>
</head>
<title>Dynamic Drop Down List</title>
<body>
<?
$sql="select * from faculty";
$re=mysql_query($sql);
?>
<form id="formname" name="formname" method="post" action="submitform.asp" >
<table width="50%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="41%" align="right" valign="middle">Category :</td>
<td width="59%" align="left" valign="middle"><select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
<option value="">โปรดเลือกข้อมูล</option>
<? while ($data=mysql_fetch_array($re)){?>
<option value="<?=$data[faculty_id]?>"><?=$data[faculty_name]?></option>
<? }?>
</select></td>
</tr>
<tr>
<td align="right" valign="middle">Sub Category :
</td>
<td align="left" valign="middle"><script type="text/javascript" language="JavaScript">
document.write('<select name="subcategory"><option value="">Select Sub-Category</option></select>')
</script>
<noscript><select name="subcategory" id="subcategory" >
<option value="">Select Sub-Category</option>
</select>
</noscript></td>
</tr>
</table>
</form>
</body>
</html>
|
|
|
|
|
Date :
2011-04-11 13:45:17 |
By :
the_cop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีแนวทางระบบสืบค้นงานปริญญานิพนธ์บ้างไหมค่ะ
|
ประวัติการแก้ไข 2012-04-09 13:31:14
|
|
|
|
Date :
2012-04-09 13:29:44 |
By :
กร |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|