เขียน PHP HTML ต้องการเลือกค่า checkbox สำหรับคุณครู ส่งค่าไปอีกหน้าหนึ่ง
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา เขียน PHP HTML ต้องการเลือกค่า checkbox สำหรับคุณครู ส่งค่าไปอีกหน้าหนึ่ง
เขียน PHP HTML ต้องการเลือกค่า checkbox สำหรับคุณครู ส่งค่าไปอีกหน้าหนึ่ง
เขียน PHP HTML JAVASCRIPE ต้อง -เลือก checkbox สำหรับคุณครู แล้วส่งค่าไปหน้า check_login.php
-เลือก checkbox สำหรับนักเรียน แล้วส่งค่าไปหน้า check_login_student.php

-เลือก checkbox สำหรับนักเรียน แล้วส่งค่าไปหน้า check_login_student.php
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | < body > < table width = "900" border = "0" align = "center" cellpadding = "0" cellspacing = "0" bgcolor = "#FFFFFF" "> < tr > < td width = "66" >< img src = "img/ppy_logo.jpg" width = "66" height = "65" ></ td > < td width = "824" align = "center" bgcolor = "#003366" >< p class = "style1" >< span class = "style3" >ระบบประเมินผลนักเรียน โรงเรียนปลูกปัญญา</ span >< br > </ p > </ td > </ tr > < tr > < td colspan = "2" > </ td > </ tr > < tr > < td >< form name = "form1" method = "post" action = "check_login.php" > < br > < table border = "0" align = "center" cellpadding = "0" cellspacing = "1" style = "width: 300px" > < tbody > < tr > < td colspan = "2" >System Login< br ></ td > </ tr > < tr > < td align = "left" > Username:</ td > < td >< input name = "txtUsername" type = "text" id = "txtUsername" > </ td > </ tr > < tr > < td align = "left" > Password: </ td > < td >< input name = "txtPassword" type = "password" id = "txtPassword" ></ td > </ tr > < tr > < td > < input name = "data_item1" type = "checkbox" class = "css_data_item" id = "data_item1" value = "1" >สำหรับคุณครู</ input ></ td > < td > < input name = "data_item2" type = "checkbox" class = "css_data_item" id = "data_item2" value = "2" >สำหรับนักเรียน</ input ></ td > </ tr > < tr > < td > </ td > < td >< input type = "submit" name = "Submit" value = "Login" ></ td > </ tr > </ tbody > </ table > < br > </ form ></ td > </ tr > < tr > < td colspan = "2" align = "center" bgcolor = "#003366" >< p >< strong >< strong >< br > < span class = "style4" >Copyright ©</ span ></ strong ></ strong >< span class = "style4" > 2019 Information Technllogy</ span ></ p > < p > </ p ></ td > </ tr > </ table > < script type = "text/javascript" > $(function(){ $(".css_data_item").click(function(){ // เมื่อคลิก checkbox ใดๆ if($(this).prop("checked")==true){ // ตรวจสอบ property การ ของ var indexObj=$(this).index(".css_data_item"); // $(".css_data_item").not(":eq("+indexObj+")").prop( "checked", false ); // ยกเลิกการคลิก รายการอื่น } }); }); </ script > </ body > |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
หาส่วนที่เกี่ยวข้อง ซึ่งจะมีสองส่วน คือ ตรง
action="check_login.php" กับ
กับ checkbox ซึ่งจริงๆ ถ้าเงื่อนไขให้เลือกอย่างใด อย่างหนึ่งควรใช้เป็น radio แทน
เพราะถ้าเป็น radio แล้วเราไม่ต้องมาเขียนสคริปคำสั่งเพิ่มเหมือนใช้ checkbox
แนวทาง คือเมื่อคลิกเลือก checkbox ใดๆ ให้ค่า ของ action เปลี่ยนไปตามที่ต้องการ
โดยใช้เงื่อนไข ค่าของ checkbox ที่ถูกเลือก
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $( ".css_data_item" ).click( function (){ // เมื่อคลิก checkbox ใดๆ if ($( this ).prop( "checked" )== true ){ // ตรวจสอบ property การ ของ var indexObj=$( this ).index( ".css_data_item" ); // $( ".css_data_item" ).not( ":eq(" +indexObj+ ")" ).prop( "checked" , false ); // ยกเลิกการคลิก รายการอื่น var checkVal = $( this ).val(); // ค่าของ checkbox ที่เลือก console.log(checkVal); // var formObj = $( "form[name='form1']" ); // jquery form object var newFormActionValue = "check_login.php" ; if (checkVal== "1" ){ newFormActionValue = "check_login.php" ; } else { newFormActionValue = "check_login_student.php" ; } formObj.attr( "action" ,newFormActionValue); // change form action value var formAction = formObj.attr( "action" ); // form action value console.log(formAction); } }); |

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