<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script> function update (el) { var $F = $('tr.showF'); var $M = $('tr.showM'); if (el.checked && el.value === 'M') { $F.hide(); $M.show(); } else { $F.show(); $M.hide(); } } $(function () { update($('input:checked')[0]); $('input[name="fromType"]').change(function () { update(this); }); }); </script> </head> <body> <form action="Save.php" name="frmAdd" method="post"><br> อายุ <input type="text" name="sname" id="textfield"> <br> <table id="CurrentProperty"> <tr> <td colspan="3"> <p> <label>เพศ:</label> <br/> <input type="radio" value="M" name="fromType" checked="checked" /> ชาย <input type="radio" value="F" name="fromType" /> หญิง</p> <br> </td> </tr> <tr class="showF"> <td colspan="3">ตารางหญิง <table width="215" border="1"> <tr> <th width="153"> <div align="center">111</div></th> </tr> <tr> <td> </td> </tr> </table> <table width="215" border="1"> <tr> <th width="153"> <div align="center">222</div></th> </tr> <tr> <td> </td> </tr> </table> <br> <input type="submit" name="submit" value="submit"> </td><br> </tr> <tr class="showM"> <td colspan="3"> ตารางชาย <table width="218" border="1"> <tr> <th> <div align="center">333</div></th> </tr> <tr> <td> </td> </tr> <tr> <th width="91"> <div align="center">444</div></th> </tr> <tr> <td> </td> </tr> </table> <br> <input type="submit" name="submit" value="submit"> </form> </body> </html>
<script> function myFunction() { var x = document.getElementById("users").value; document.getElementById("numb").innerHTML = x; } </script> อายุุ<input type="text" name="users" id="users" onkeyup="myFunction()"> <p id="numb"></p> <br>
<script> function myFunction() { var x = document.getElementById("users").value; if (x.length > 0) { alert(x); } document.getElementById("numb").innerHTML = x; } </script> อายุุ<input type="text" name="users" id="users" onkeyup="myFunction()"> <p id="numb"></p> <br>
var users= $("input[name=users]").val(); if (users.length > 0) { $("#numb").after(users); }
<html> <head> <meta charset="UTF-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script> $(document).ready(function() { $('#showF_under12').hide(); //ซ่อน $('#showF_over12').hide(); //ซ่อน $('#showM_under12').hide(); //ซ่อน $('#showM_over12').hide(); //ซ่อน $('#frmAdd').on('click','#submit',function(){ alert("ทำงานเพราะคลิกปุ่ม submit "); var age = $("input[name=age]").val(); //รับค่า อายุ alert("แสดงอายุ : " + age); var sex = $("#frmAdd input[name=sex]:checked").val(); alert("แสดงเพศ : " + sex); //ค่าที่รับมาเป็น M ชาย if(sex == 'M'){ if(age > 12){ // อายุมากกว่า 12 $('#showM_over12').show(); $('#showF_under12').hide(); //ซ่อน $('#showF_over12').hide(); //ซ่อน $('#showM_under12').hide(); //ซ่อน }else{ // อายุน้อยกว่า 12 $('#showM_under12').show(); $('#showF_under12').hide(); //ซ่อน $('#showF_over12').hide(); //ซ่อน $('#showM_over12').hide(); //ซ่อน } }else{ //ค่าที่รับมาไม่ใช่ M แสดงว่ามีค่าเป็น F if(age > 12){ // อายุมากกว่า 12 $('#showF_over12').show(); $('#showF_under12').hide(); //ซ่อน $('#showM_under12').hide(); //ซ่อน $('#showM_over12').hide(); //ซ่อน }else{ // อายุน้อยกว่า 12 $('#showF_under12').show(); $('#showF_over12').hide(); //ซ่อน $('#showM_under12').hide(); //ซ่อน $('#showM_over12').hide(); //ซ่อน } } }); }); </script> </head> <body> <form action="Save.php" id="frmAdd" name="frmAdd" method="post"> <hr> อายุ <input type="text" name="age" id="age"> <hr> <label>เพศ:</label> <br/> <input type="radio" value="M" name="sex" /> ชาย <input type="radio" value="F" name="sex" /> หญิง <hr> <div id="showF_under12">ผู้หญิง อายุ < 12 แสดง 111</div> <div id="showF_over12">ผู้หญิง อายุ > 12 แสดง 222</div> <div id="showM_under12">ผู้ชาย อายุ < 12 แสดง 333</div> <div id="showM_over12">ผู้ชาย อายุ > 12 แสดง 444</div> <hr> <input type="button" name="submit" id="submit" value="submit"> </form> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง