|
 |
|
อยากทำ html listbox 3 ชั้นอะครับ ตอนนี้ทำได้แค่ 2 ชั้น |
|
 |
|
|
 |
 |
|
คือผมไม่รู้ต้องไปเพิ่มเงื่อนไขอีกตรงไหนอะครับ
ตอนนี้ทำ เลือก คณะ แล้ว ก็ขึ้นภาควิชาให้เลือกได้แล้ว คือ แค่ 2 ชั้น
แต่ผมอยากให้เลือก ภาควิชาแล้ว สาขาขึ้นมาของแต่ละภาควิชานั้นๆ ครับ
เช่น เลือก ภาควิชา วิทยาศาสตร์ แล้วขึ้นแค่ เคมี กับ ชีวะ อ่ะครับ
ตอนนี้ผมเลยเขียนให้ ขึ้นสาขา ทั้งหมด ของแต่ละคณะ ครับ
<body>
<p class="style1"> แสดงรายชื่อของนักศึกษาในแต่ละสาขา</p>
<form name="form1" method="post" action="">
<table width="505" border="0" cellspacing="0" cellpadding="5">
<th scope="col"><td><select name="select1" onChange="changeSelect2(this)">
<option value="0" selected>กรุณาเลือกภาควิชา</option>
<option value="scin">คณะวิทยาศาสตร์</option>
<option value="engi">คณะวิศวกรรมศาสตร์</option>
</select>
</td>
<td><select name="select2" >
<option selected>กรุณาเลือกภาควิชา</option>
</select>
</td>
<td><select name="select3" >
<option selected>กรุณาเลือกสาขา</option>
</select>
</td>
</th>
</table>
<br>
<script language="javascript">
function changeSelect2(obj){
var theform = obj.form;
theform.select2.length=0;
theform.select3.length=0;
switch(obj.value){
case "0":
{
theform.select2.options[0]=new Option('กรุณาเลือกภาควิชา','กรุณาเลือกภาควิชา');
theform.select3.options[0]=new Option('กรุณาเลือกสาขา','กรุณาเลือกสาขา');
theform.select2=false;
theform.select3=false;
}
break;
case"scin":
{
theform.select2.options[0]=new Option('กรุณาเลือกภาควิชา','กรุณาเลือกภาควิชา');
theform.select2.options[1]=new Option('วิทยาศาสตร์','science');
theform.select2.options[2]=new Option('คอมพิวเตอร์','com');
theform.select3.options[0]=new Option('กรุณาเลือกสาขา','กรุณาเลือกสาขา');
theform.select3.options[1]=new Option('เคมี','chem');
theform.select3.options[2]=new Option('ชีวะ','bio');
theform.select3.options[3]=new Option('วิทยาการคอมพิวเตอร์','com');
theform.select3.options[4]=new Option('เทคโนโลยีสารสนเทศ','it');
theform.select2=false;
theform.select3=false;
}
break;
case"engi":
{
theform.select2.options[0]=new Option('กรุณาเลือกภาควิชา','กรุณาเลือกภาควิชา');
theform.select2.options[1]=new Option('วิศวกรรมศาสตร์','civil');
theform.select2.options[2]=new Option('ชีวภาพ','bio');
theform.select3.options[0]=new Option('กรุณาเลือกสาขา','กรุณาเลือกสาขา');
theform.select3.options[1]=new Option('โยธา','civil');
theform.select3.options[2]=new Option('อาหาร','food');
}
break;
}
}
</script>
</p>
</form>
</body>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-01-05 19:48:16 |
By :
Sacrifice |
View :
2891 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือผมเขียนแบบนี้เพราะว่า ผมอยากกำหนดเอง อะครับ
อันข้างบนนั้นคือ ไปดึงจากฐานข้อมูลมาอยู่ใน listbox
ผมไม่มีฐานข้อมูลของสาขาและภาควิชาด้วยครับ
|
 |
 |
 |
 |
Date :
2010-01-05 20:17:33 |
By :
Sacrifice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
theform.select2=false; บรรทัดนี้เอาไว้ทำอะไรเหรอคับ ผมไม่รู้จริงๆ
|
 |
 |
 |
 |
Date :
2010-01-05 20:29:53 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
theform.select2=false;
theform.select3=false;
ไม่ใส่ก็ไม่เป็นไร ครับ ตัวอย่างจากที่ผมเอา มา modify เขาเขียนไว้ครับ
|
 |
 |
 |
 |
Date :
2010-01-05 20:40:59 |
By :
Sacrifice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็น่าจะทำแบบมีฐานข้อมูลนะ ถ้าสมมุติ เค้าเพิ่มสาขามา หรือแก้ไขอะไร ได้ไม่ต้องมานั่งแก้โค้ดทีหลัง
เพิ่มไปในฐานข้อมูลเลยมันสะดวกกว่าอยู่แล้ว มาแก้โค้ดทีหลัง อาจจะลืมแล้วก็ได้ว่าทำยังไง
เอาตามลิงค์นี้หละครับ ดีแล้ว ผมก็เอาไปประยุกต์ใช้อยู่เหมือนกัน ใช้ง่ายดีครับ
https://www.thaicreate.com/community/dependant-listmenu-dropdownlist.html
|
 |
 |
 |
 |
Date :
2010-01-05 21:59:30 |
By :
indysoft |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|