Note that there are some explanatory texts on larger screens.

plurals
  1. PODeleting HTML tables rows
    text
    copied!<p>I know there are like thousands of answers on Stack Overflow about this specific topic, but I have been reading them for 3 days and nights already trying to apply solutions to my code with no success.</p> <p>The problem is that <code>addRow</code> works fine, but <code>DeleteRow</code> doesn't work at all.</p> <p>Here is my HTML:</p> <pre><code>&lt;input type="button" value="add" onClick="addRow('dataTable')" /&gt; &lt;input type="button" value="delete" onclick="deleteRow(this)"/&gt; &lt;p&gt;&lt;/p&gt; &lt;/p&gt; &lt;/table&gt; &lt;table id="dataTable" class="cv" border="1"&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="text" style="width:100%" placeholder="ievadiet valodu"&gt; &lt;/td&gt; &lt;td&gt; &lt;select id="BX_gender" name="BX_gender" required="required"&gt; &lt;option&gt;dzimtā valoda&lt;/option&gt; &lt;option&gt;teicami&lt;/option&gt; &lt;option&gt;labi&lt;/option&gt; &lt;option&gt;viduvēji&lt;/option&gt; &lt;option&gt;pamatzināšanas&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;select id="BX_gender" name="BX_gender" required="required"&gt; &lt;option&gt;teicami&lt;/option&gt; &lt;option&gt;labi&lt;/option&gt; &lt;option&gt;viduvēji&lt;/option&gt; &lt;option&gt;pamatzināšanas&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;select id="BX_gender" name="BX_gender" required="required"&gt; &lt;option&gt;teicami&lt;/option&gt; &lt;option&gt;labi&lt;/option&gt; &lt;option&gt;viduvēji&lt;/option&gt; &lt;option&gt;pamatzināšanas&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/fieldset&gt; </code></pre> <p>javascript:</p> <pre><code>function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; if (rowCount &lt; 5) { var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for (var i = 0; i &lt; colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; } } else { alert("Maksimālais ierakstu skaits ir 7."); } } function DeleteRow(o) { //no clue what to put here? var p = o.parentNode.parentNode; p.parentNode.removeChild(p); } </code></pre> <p>Here is a fiddle with code working (only the <code>addRow</code> function): <a href="http://jsfiddle.net/7AeDQ/690/" rel="nofollow">http://jsfiddle.net/7AeDQ/690/</a></p>
 

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