<script type="text/javascript"> $(function(){ $("#addRow").click(function(){ var NR =""; NR="<tr>"; NR+="<td width=\"60\">"; NR+="<input type=\"text\" name=\"Scholarships_year\" id=\"Scholarships_year\" size=\"10\" />"; NR+="</td>"; NR+="<td width=\"120\">"; NR+="<input type=\"text\" name=\"Scholarships_name\" id=\"Scholarships_name\" size=\"20\" />"; NR+="</td>"; NR+="<td width=\"120\">"; NR+="<input type=\"text\" name=\"Scholarships_kind\" id=\"Scholarships_kind\" size=\"20\" />"; NR+="</td>"; NR+="<td width=\"120\">"; NR+="<input type=\"text\" name=\"Scholarships_money\" id=\"Scholarships_money\" size=\"20\" />"; NR+="</td>"; NR+="</tr>"; //$("#myTbl").append($("#firstTr").clone()); $("#myTbl").append($(NR)); }); $("#removeRow").click(function(){ if($("#myTbl tr").size()>2){ $("#myTbl tr:last").remove(); }else{ alert("ต้องมีรายการข้อมูลอย่างน้อย 1 รายการ"); } }); $('input[name="toon"]').click(function(){ var Ck = $(this).val(); if(Ck=="no"){ $('#DivTable').hide(); }else{ $('#DivTable').show(); } }); }); </script> <div id="DivTable"> <table id="myTbl" width="70" border="1" style="display:"> <tr> <td align="center">ปีการศึกษา</td> <td align="center">ชื่อทุน</td> <td align="center">ประเภท</td> <td align="center">จำนวนเงิน</td> </tr> <tr id="firstTr"> <td width="10"><input name="Scholarships_year" type="text" id="Scholarships_year" size="10" /></td> <td width="20"><input name="Scholarships_name" type="text" id="Scholarships_name" size="20" /></td> <td width="20"><input name="Scholarships_kind" type="text" id="Scholarships_kind" size="20" /></td> <td width="20"><input name="Scholarships_money" type="text" id="Scholarships_money" size="20" /></td> </tr> </table> <p> <button id="addRow" type="button">+</button> <button id="removeRow" type="button">-</button> </p> </div>
$("#your_text").keyup(function(){ $index = $("#your_text").val(); if($index > 0) { for(var i = 1; i <= index ; i++) { //สร้างตารางที่ คุณต้องการ } } else { alert(กรอกมากกว่า 0) } });
<input type = text id = Scholarships_year"+i
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> $("#your_text").keyup(function(){ $index = $("#your_text").val(); if($index > 0) { for(var i = 1; i <= index ; i++) { var NR =""; NR="<tr>"; NR+="<td width=\"140\">"; NR+="<input type=\"text\" name=\"num1\" id=\"num1\" />"; NR+="</td>"; NR+="<td width=\"140\">"; NR+="<input type=\"text\" name=\"num2\" id=\"num2\" />"; NR+="</td>"; NR+="<td width=\"140\">"; NR+="<input type=\"text\" name=\"num3\" id=\"num3\" />"; NR+="</td>"; NR+="</tr>" } } else { alert("กรอกมากกว่า 0") } }); </script> </head> <body> <form id="form1" name="form1" method="post" > <p> <input type="text" name="your_text" id="your_text" /> </p> <table id="myTbl" width="420" border="1" cellspacing="2" cellpadding="0"> <tr> <td align="center">NAME</td> <td align="center">lastname</td> <td align="center">lastname</td> </tr> <tr id="firstTr"> <td width="140"><input type="text" name="name1" id="name1" /></td> <td width="140"><input type="text" name="name2" id="name2" /></td> <td width="140"><input type="text" name="name3" id="name3" /></td> </tr> </table>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง