<html> <script type="text/javascript"> function sub_details1(){ var det = document.getElementById('details'); //alert(det); for (i = 0; i < det.length; i++){ if(det[i].value ==""){ alert('กรุณากรอกรายละเอียดด้วย'); return false; }else{ document.getElementById("frm2").action= "prc_savedetails_bushistory.php"; frm2.submit(); } } } </script> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <body > <form id="frm2" name="frm2" method="post" > <input type="text" id="details[]" name="details[]" value=""><br> <input type="text" id="details[]" name="details[]" value=""><br> <input type="text" id="details[]" name="details[]" value=""><br> <input type="submit" id="sub_details" name="sub_details" value="บักทึกข้อมูล" onclick="return sub_details1();"> </form> </body> </html>
<input type="text" id="details[]" name="details[]" value="" rel="1"><br> <input type="text" id="details[]" name="details[]" value="" rel="2"><br> <input type="text" id="details[]" name="details[]" value="" rel="3"><br> <button id="btnSave">Save</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(function(){ $('#btnSave').on('click',function(){ $('input[id]').each(function(index, element) { if($(this).val() == ''){ alert('Input '+$(this).attr('rel')); $(this).focus(); return false; } }); }); }); </script>
<input type="text" id="details[]" name="details[]" value="" rel="1"><br> <input type="text" id="details[]" name="details[]" value="" rel="2"><br> <input type="text" id="details[]" name="details[]" value="" rel="3"><br> <button id="btnSave">Save</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(function(){ $('#btnSave').on('click',function(){ $('input[id="details[]"]').each(function(index, element) { if($(this).val() == ''){ alert('Input '+$(this).attr('rel')); $(this).focus(); return false; } }); }); }); </script>
เปลี่ยน ตัวแปร var fileup = document.getElementsByClassName('ID_fileUpload'); เป็น var fileup = document.querySelectorAll('.ID_fileUpload');
var fileup = document.querySelectorAll('ID_fileUpload');
<input type="text" id="details[]" name="details[]" class="ID_fileUpload" value="" ><br> <input type="text" id="details[]" name="details[]" class="ID_fileUpload" value="" ><br> <input type="text" id="details[]" name="details[]" class="ID_fileUpload" value="" ><br> <button id="btnSave" onclick="return chknull()">Save</button> <script> function chknull(){ var fileup = document.querySelectorAll('ID_fileUpload'); console.log(fileup); for(i = 0; i < fileup.length; i++) { console.log('val = '+fileup[i].value); if(fileup[i].value === ""){ alert('กรุณาเลือกรูปภาพ เพื่อทำการอัพโหลด'); fileup[i].focus(); return false; } } } </script>
<html> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <body> <form id="frm2" name="frm2" method="post" > <input type="text" class="details" name="details[]" value=""><br> <input type="text" class="details" name="details[]" value=""><br> <input type="text" class="details" name="details[]" value=""><br> <input type="submit" id="sub_details" name="sub_details" value="บักทึกข้อมูล" onclick="return sub_details1();"> </form> <script type="text/javascript"> function sub_details1(){ var elem_details = document.getElementsByClassName('details'); var loop = elem_details.length; var success = true; for (i = 0; i < loop; i++){ if(elem_details[i].value ==""){ success = false; } } if(success){ document.getElementById("frm2").action= "prc_savedetails_bushistory.php"; frm2.submit(); }else{ alert('กรุณากรอกรายละเอียดด้วย'); return false; } } </script> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง