Here is the code:
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <script language="javascript">
- function AddRows()
- {
- //find the table element
- var tableelement=document.getElementById("mytable")
- //find the value in no of rows control
- var rows=document.getElementById("noofrows").value;
- //find the existing no of rows in the table
- var tablerowcount=tableelement.rows.length;
- var currowcount=tablerowcount;
- for(i=1;i < rows;i++ ) {
- //insert a row as the last row of the table
- var row=tableelement.insertRow(currowcount);
- //insert a first cell/td in the newly added row
- var cellid=row.insertCell(0);
- cellid.innerHTML="<b>" + currowcount +"</b>";
- //insert a second cell/td in the newly added row
- var cellid2=row.insertCell(1);
- cellid2.innerHTML="<input value='' id='" + currowcount +"_name' /> ";
- var cellid3=row.insertCell(1);
- cellid3.innerHTML="<input value='' id='" + currowcount +"_name' /> ";
- var cellid4=row.insertCell(1);
- cellid4.innerHTML="<input value='' id='" + currowcount +"_name' /> ";
- var cellid5=row.insertCell(1);
- cellid5.innerHTML="<input value='' id='" +currowcount +"_name' /> ";
- var cellid6=row.insertCell(1);
- cellid6.innerHTML="<input value='' id='" +currowcount+"_name' /> ";
- //increment the table row count variable
- var currowcountcurrowcount=currowcount++;
- }
- }
- </script>
- </head>
- <body>
- <form method="post" action="insert.php>
- Carton Number :<input type="text" name="cn"> <br>
- Business Unit :<input type="text" name="bu"> <br>
- No of Files :<input type="noofrows" id="noofrows" value="1" name="nof" />
- <input name="add" id="add" type="button" value="Add" onClick="AddRows()"/>
- <table name="mytable" id="mytable" border=1>
- <tr>
- <td>
- <b>SN</b>
- </td>
- <td>
- <b>From</b>
- </td>
- <td>
- <b>To</b>
- </td>
- <td>
- <b>Range</b>
- </td>
- <td>
- <b>Document Category</b>
- </td>
- <td>
- <b>Document Type</b>
- </td>
- </tr>
- <tr>
- <td>
- <b>1</b>
- </td>
- <td>
- <input value="" id='1_name' >
- </b>
- </td>
- <td>
- <input value="" id='1_name'/>
- </b>
- </td>
- <td>
- <input value="" id='1_name' />
- </b>
- </td>
- <td>
- <Select id='select' />
- <option name="option" value="finance">Finance Documents</option>
- <option name="option" value="hr">HR Documents</option>
- <option name="option" value="test">test</option
- </Select>
- </b>
- </td>
- <td>
- <Select id='select' />
- <option name="option" value="CP">Cash movement</option>
- <option name="option" value="PV">Payment Voucher</option>
- <option name="option" value="RV">RV</option
- </Select>
- </b>
- </td>
- </tr>
- </table>
- <br/>
- <input type="submit"name="submit"value="Submit"/>
- </form>
- </body>
- </html>