What is the way to add multiple rows dynamically to a table using javascript?
-
hi, 1)i have a table "maintable" 2)inside "maintable" i have 3 rows calles "row1" "row2" "row3". 3)in "row1" i have [+] and[-] button to add and delete respectively, when i click [+] "row1" "row2" "row3" should add at once, and same for [-] to delete. 4) and also i have "Address Seq Num " in "row1" the value of this should be 1,2,3..like serial number for the sucessive additon of rows. 5)and in "row3" i have table called "innertable" ,inside this it has body called "innerbody" inside this it has a row called "innerrow" this "innerrow also had [+][-] buttons. 6)this "innerrow" should be added when [+] is clicked and shluld be deleted when [-] button clicked. please help me..i'm strucked in this... <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Address Detail</title> <SCRIPT language="javascript"> </SCRIPT> </head> <div id="content" style=";height:200px;width:450px;float:left;"> <table align="center" id="maintable" style="width:200%" > <tbody id="tablebody" > <tr id="row1"> <td> <div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF"> <table align="center" style="width:99%" > <tr style="background-color:#1E90FF"> <td align="left" style="width:30%"> Address Seq Num <input style="float:center;width:50px" type="text" value="1" readonly id="seqm" name="seq" readonly> </td> <td width="50%" > <input style="width:80%" type="text" value="Reg.office/Primary Office"> </td> <td align="right"> <input style="width:30px" type="button" onclick="cloneRow1();" value="+" > <input style="width:30px" type="button" value="-" onclick="delRow1();"> </td> </tr> </table> </div> </td> </tr> <tr id="row2" > <td> <div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF"> <table align="center" style="width:99%" > <tr > <td align="left" > Effective Date: <input style="position:absolute;left:30.1%;background-color:white" size="8.9px" type="text" name="effdte" class="tcal" value="<%=(String)session.getAttribute("efdate") %>" readonly> </td> <td style="width:50%"align="left"> Effective Status: <select name="eff_status" style="float:right;width:105px" id="estatus" > <option value="" > </option> </select> </td> </tr> <tr> <td> Country: <select style="position:absolute;left:30.3%;width:105px" name="country"> <option value=""></option> </select> </td> </tr> <tr> <td> State: <select style="position:absolute;left:30.3%;width:105px" name="state"> </select> </td> </tr> <tr> <td> City: <input style="position:absolute;left:30.3%;float:right" type="text" name="city" value="<%=(String)session.getAttribute("city") %>" > </td> </tr> <tr> <td> Area: <input style="position:absolute;left:30.3%;float:right" type="text" name="area" value="<%=(String)session.getAttribute("county") %>" > </td> </tr> <tr> <td> Postal Pin: <input style="position:absolute;left:30.3%;float:right" type="text" name="ppin" value="<%=(String)session.getAttribute("postal") %>" > </td> </tr> <tr> <td> Url <input style="position:absolute;left:30.3%;width:20%;float:right" type="text" name="url" value="<%=(String)session.getAttribute("email") %>" > </td> </tr> <tr> <td> <div id="placeholder"> <div id="template"> <fieldset> <legend class="th" id="blahblah" align="left">Buisness Address</legend> <input style="width:90%" type="text" name="address1" value="" > <input style="width:90%" type="text" name="address2" value="" > <input style="width:90%" type="text" name="address3" value="" > <input style="width:90%" type="text" name="address4" value="" > </fieldset> </div> </div> </td> </tr> </table> </div> </td> </tr> <tr id="row3"> <td> <div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF"> <table align="center" id="innertable" style="width:99%"> <tbody id="innerbody"> <tr > <td></td> <td>Phone Type </td> <td>Country code </td> <td>Phone Number </td> <td>Extension </td> </tr> <tr id="innerrow"> <td></td> <td > <select style="width:145px" name="ph"> <option value="none"><---select---></option> <option value="Mobile">Mobile</option> <option value="Landline">Land line</option> </select> </td> <td><input type="text" name="countrycode"></td> <td> <input type="text" name="ph"></td> <td><input type="text" name="ext"></td> <td align="right"> <input style="width:30px" type="button" onclick="cloneRow()"value="+" > <input style="width:30px" type="button" value="-" onclick="delRow()"> </td> </tr> </tbody> </table> </div> </td> </tr> </tbody> </table> </div> </body> </html>
-
Answer:
Check out the code of this http://www.balanarayanan.in/flipkart function addRow(){ var tbody = document.getElementById('mainbody'); var row = document.createElement('tr'); var cell = document.createElement('td'); var text = document.createTextNode(String(rows)); cell.appendChild(text); row.appendChild(cell); for(var j=0;j<coloumns;j++) { var cell = document.createElement('td'); cell.innerHTML="<div onclick='myFunction(event)' ><input class='inputbox "+String.fromCharCode(65 + j)+rows+"' value=''></input></div>"; row.appendChild(cell); } tbody.appendChild(row); rows++; window.scrollTo(0,document.height); }
Bala Narayanan at Quora Visit the source
Related Q & A:
- How to uninstall Firefox add-on using javascript?Best solution by Stack Overflow
- How do I remove a site from IIS7 using JavaScript?Best solution by Server Fault
- How to connect to a Pervasive Database using javascript?Best solution by Stack Overflow
- How to add primary key from multiple table as a foreign key in a table in sql server 2008?Best solution by stackoverflow.com
- How Can I add Latitude, Longitude dynamically in Javascript?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.