Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd/Delete table rows dynamically using JavaScript
    primarykey
    data
    text
    <p>I'm trying to add/delete table rows following <a href="http://www.w3schools.com/js/tryit.asp?filename=try_dom_table_insertrow" rel="noreferrer">this example </a> and <a href="http://www.w3schools.com/js/tryit.asp?filename=try_dom_table_deleterow" rel="noreferrer"> this example</a>. </p> <p>Here's my code: </p> <p><strong>HTML Form</strong></p> <pre><code>&lt;div id="POItablediv"&gt; &lt;input type="button" id="addPOIbutton" value="Add POIs"/&gt;&lt;br/&gt;&lt;br/&gt; &lt;table id="POITable" border="1"&gt; &lt;tr&gt; &lt;td&gt;POI&lt;/td&gt; &lt;td&gt;Latitude&lt;/td&gt; &lt;td&gt;Longitude&lt;/td&gt; &lt;td&gt;Delete?&lt;/td&gt; &lt;td&gt;Add Rows?&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;&lt;input size=25 type="text" id="latbox" readonly=true/&gt;&lt;/td&gt; &lt;td&gt;&lt;input size=25 type="text" id="lngbox" readonly=true/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="button" id="delPOIbutton" value="Delete" onclick="deleteRow(this)"/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="button" id="addmorePOIbutton" value="Add More POIs" onclick="insRow()"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p><strong>JavaScript</strong></p> <pre><code>function deleteRow(row) { var i=row.parentNode.parentNode.rowIndex; document.getElementById('POITable').deleteRow(i); } function insRow() { var x=document.getElementById('POITable').insertRow(1); var c1=x.insertCell(0); var c2=x.insertCell(1); c1.innerHTML="NEW CELL1"; c2.innerHTML="NEW CELL2"; } </code></pre> <p>Now, as you can see, In my table I have text fields and buttons. What I want: </p> <ol> <li><p>Just to repeat the structure of the row. I can't do it right now since innerHTM just takes texts. How can I insert a textfield or label?</p></li> <li><p>The ids of the textfields should also be different since I'll retrieve the values later to put it in a database.</p></li> <li><p>I want to put a function to increment the number of POIs as well</p></li> </ol> <p>Can anyone help me out please? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload