การเช็คค่าข้อมูล checkbox ,, ขอคำแนะนำด้วย
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา การเช็คค่าข้อมูล checkbox ,, ขอคำแนะนำด้วย
การเช็คค่าข้อมูล checkbox ,, ขอคำแนะนำด้วย
ขอคำแนะนำด้วยค่ะ คือว่าต้องการให้เช็คค่าของ checkbox ว่าถ้าไม่เลือกตัวที่ 1 จะเลือกตัวที่ 2 ไม่ได้
และถ้าไม่เลือกตัวที่ 1 และ 2 จะไม่สามารถเลือกตัวที่ 3 ได้ค่ะ
ขอแนวทางในการเขียน code หน่อยนะค่ะ ขอบคุณค่ะ

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
ลองใช้ jQuery ดู โดย
1.เพิ่ม class ให้ checkbox ทุกตัวเท่ากับ class="my_checkbox"
2.ใช้ jQuery ในการจัดการ ดังตัวอย่างโค้ดด้านล่าง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <form id= "form2" name= "form2" method= "post" action= "" > <table width= "500" border= "1" cellspacing= "0" cellpadding= "0" > <tr> <td width= "100" > </td> <td width= "100" > </td> <td width= "100" > </td> <td width= "100" > </td> </tr> <tr> <td align= "left" ><input type= "checkbox" name= "checkbox" id= "checkbox" class = "my_checkbox" /></td> <td align= "left" ><input type= "checkbox" name= "checkbox2" id= "checkbox2" class = "my_checkbox" /></td> <td align= "left" ><input type= "checkbox" name= "checkbox3" id= "checkbox3" class = "my_checkbox" /></td> <td align= "left" ><input type= "checkbox" name= "checkbox8" id= "checkbox8" class = "my_checkbox" /></td> </tr> <tr> <td align= "left" ><input type= "checkbox" name= "checkbox4" id= "checkbox4" class = "my_checkbox" /></td> <td align= "left" ><input type= "checkbox" name= "checkbox5" id= "checkbox5" class = "my_checkbox" /></td> <td align= "left" ><input type= "checkbox" name= "checkbox6" id= "checkbox6" class = "my_checkbox" /></td> <td align= "left" ><input type= "checkbox" name= "checkbox7" id= "checkbox7" class = "my_checkbox" /></td> </tr> </table> </form> <script type= "text/javascript" > $( function (){ $( ".my_checkbox" ).click( function (){ var prevCheckbox=$(this).parent( "td" ).prev( "td" ).find( ".my_checkbox" ).attr( "checked" ); if (prevCheckbox!=undefined && prevCheckbox==false){ return false; } }); }); </script> |
ตัวอย่าง

ความคิดเห็นที่
2
ขอบคุณค่ะ จะลองไปปรับดูนะค่ะ ^^

ขอบคุณทุกการสนับสนุน
![]()