<html> <head> <script language="JavaScript" src="./frmsubmit.js"></script> </head> <body > <form name = "frmtest" method="post" onSubmit="JavaScript:return fncSubmit(<?=$i?>);" > <table width="200" border="1"> <tr> <th width="200"> <div align="left">Part NO </div></th> <th width="200"> <div align="left">Part Name </div></th> <th width="100"> <div align="left">Qty</div></th> </tr> <? for($i=0;$i<5;$i++) { ?> <tr> <td><div align="left"><input type="text" name="txtpartNO<?=$i?>" id="txtpartNO<?=$i?>" size="10"></div></td> <th><div align="left"><input type="text" name="txtpartname<?=$i?>" id="txtpartname<?=$i?>" size="20" ></div></th> <th><div align="left"><input type="text" name="txtqty<?=$i?>" id="txtqty<?=$i?>" size="10"></div></th> </tr> <? } ?> </table> <input type="submit" name="submit" value="submit" > </form> </body> </html>
function fncSubmit(i) { if(document.getElementById("txtpartNO" + i).value == "") { alert('Please input Part NO'); document.getElementById("txtpartNO" + i).focus(); return false; } else if(document.getElementById("txtpartname" + i).value == "") { alert('Please input Part Name'); document.getElementById("txtpartname" + i).focus(); return false; } else if(document.getElementById("txtqty" + i).value == "") { alert('Please input Qauntity'); document.getElementById("txtqty" + i).focus(); return false; } else { return false; } }
<html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body > <form name="frmtest" id="frmtest" method="post" action="www.google.com"> <table width="200" border="1"> <tr> <th width="200"> <div align="left">Part NO </div></th> <th width="200"> <div align="left">Part Name </div></th> <th width="100"> <div align="left">Qty</div></th> </tr> <tbody> <?php for($i=0;$i<2;$i++) { ?> <tr> <td><div align="left"><input type="text" name="txtpartNO<?php echo $i?>" id="txtpartNO<?php echo $i?>" size="10"></div></td> <th><div align="left"><input type="text" name="txtpartname<?php echo $i?>" id="txtpartname<?php echo $i?>" size="20" ></div></th> <th><div align="left"><input type="text" name="txtqty<?php echo $i?>" id="txtqty<?php echo $i?>" size="10"></div></th> </tr> <?php } ?> </tbody> </table> <input type="submit" name="submit" value="submit" > </form> <script type="text/javascript"> var form1 = $("form#frmtest"); form1.submit(function(event){ event.preventDefault(); var errcount=0; $("tbody input:text",form1).each(function(){ if($(this).val() == ""){ errcount++; alert($(this).attr("name")); $(this).focus(); } }); if(errcount == 0){ form1.submit(); } }) </script> </body> </html>
<?php for($i=0;$i<2;$i++) { ?> <tr> <td><div align="left"><input type="text" name="txtpartNO<?php echo $i?>" id="txtpartNO<?php echo $i?>" size="10"></div></td> <td><div align="left"><input type="text" name="txtpartname<?php echo $i?>" id="txtpartname<?php echo $i?>" size="20" ></div></td> <td><div align="left"><input type="text" name="txtqty<?php echo $i?>" id="txtqty<?php echo $i?>" size="10" rel="required" ></div></td> </tr> <?php } ?>
var form1 = $("form#frmtest"); form1.submit(function(event){ event.preventDefault(); var errcount=0; $("tbody input:text [rel='required']",form1).each(function(){ if($(this).val() == ""){ errcount++; alert($(this).attr("name")); $(this).focus(); } }); if(errcount == 0){ form1.submit(); } })
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง