Note that there are some explanatory texts on larger screens.

plurals
  1. POCloning whole html table (with uniq IDs) element with javascript
    primarykey
    data
    text
    <p>I somehow made my newRow() function work. Code you can see below. Now i need to clone whole table. I tried to adjust the newRow() function to do this task, obviously my attempt was unaccessful.</p> <p>My js code: </p> <pre><code>function newRow( valoda, dataTable){ var row, table, len, tags, newRow; row = document.getElementById('valoda'); table = document.getElementById('dataTable'); tags = table.getElementsByTagName('tr'); len = tags.length; newRow = row.cloneNode(true); newRow.id = "valoda_0" + len; table.appendChild(newRow); } function newTable(dataTable3){ var table, len, tags, newTable; table = document.getElementById('dataTable3'); tags = table.getElementsByTagName('table'); len = tags.length; newTable = row.cloneNode(true); newTable.id = "darbs_0" + len; table.appendChild(newRow); } </code></pre> <p>And HTML:</p> <pre><code>&lt;fieldset class="row2"&gt; &lt;legend&gt;Iemaņas un zināšanas&lt;/legend&gt; &lt;p&gt; &lt;input type="button" value="Pievienot" onClick="newRow( 'valoda', 'dataTable')" /&gt; &lt;p&gt; &lt;/p&gt; &lt;/p&gt; &lt;table class="virsraksti" border="1"&gt; &lt;tr&gt; &lt;th style="width:25%"&gt; Valoda&lt;/th&gt; &lt;th style="width:25%"&gt; Runātprasme &lt;/th&gt; &lt;th style="width:25%"&gt; Lasītprasme &lt;/th&gt; &lt;th style="width:25%"&gt; Rakstītprasme &lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table id="dataTable" class="cv" border="1"&gt; &lt;tbody&gt; &lt;tr id="valoda"&gt; &lt;td&gt; &lt;input type="text" style="width:100%;" placeholder="ievadiet valodu"&gt; &lt;/td&gt; &lt;td&gt; &lt;select id="Runatprasme_izv" name="Runatprasme_izv" 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="Lasitprasme_izv" name="Lasitprasme_izv" 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="Rakstitprasme_izv" name="Rakstitprasme_izv" 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;/tbody&gt; &lt;/table&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/fieldset&gt; &lt;fieldset class="row3"&gt; &lt;legend&gt;Datorzināšanas&lt;/legend&gt; &lt;p&gt; &lt;input type="button" value="Pievienot" onClick="newRow2( 'datori', 'dataTable2')"/&gt; &lt;/p&gt; &lt;p&gt; &lt;table&gt; &lt;th&gt; &lt;th style="width:75%"&gt; Nosaukums &lt;/th&gt; &lt;th&gt; &lt;th style="width:25%"&gt; Zināšanu līmenis &lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table id="dataTable2" class="cv" border="1"&gt; &lt;tr id="datori"&gt; &lt;td style="width:75%"&gt;&lt;input type="text" style="width:100%;" name="Dator_nos"placeholder="Ievadiet programmatūras nosaukumu"&gt;&lt;/td&gt; &lt;td&gt; &lt;select id="BX_gender" name="BX_gender" style="width:100%"&gt; &lt;option&gt;teicami&lt;/option&gt; &lt;option&gt;labi&lt;/option&gt; &lt;option&gt;pamatzināšanas&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;fieldset class="row4"&gt; &lt;legend&gt;Darba pieredze&lt;/legend&gt; &lt;p&gt; &lt;input type="button" value="Pievienot" onClick="newTable('dataTable3')" /&gt; &lt;p&gt;&lt;/p&gt; &lt;/p&gt; &lt;table id="dataTable3" class="cv" border="1"&gt; &lt;tr&gt; &lt;td style="width:5%; text-align:left"&gt; Darba vieta/Uzņēmums: &lt;/td&gt; &lt;td style="padding:0"&gt; &lt;input type="text" class="darbs"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width:5%; text-align:left"&gt; Datums no: &lt;/td&gt; &lt;td style="padding:0"&gt; &lt;input type="text" class="darbs"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width:5%; text-align:left"&gt; Datums līdz:&lt;/td&gt; &lt;td style="padding:0"&gt; &lt;input type="text" class="darbs"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width:5%; text-align:left"&gt; Ieņemamais amats:&lt;/td&gt; &lt;td style="padding:0"&gt; &lt;input type="text" class="darbs"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width:5%; text-align:left"&gt; Amata kategorija:&lt;/td&gt; &lt;td style="padding:0"&gt; &lt;input type="text" class="darbs"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; </code></pre> <p>I know there are a lot of ways to clone table rows, but since i am about to put all the input data in DB, i needed a function which creates a uniq IDs for every created element, and i know that newRow() function does that, but what about addTable() ? Will it create only unique table IDs, or is it possible to get new uniques for all the input fields in table?</p> <p>I hope u understood my twisted question. Upon a request i will add a fiddle if needed.</p> <p>Can you show me the right solution here?</p> <p>Big thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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