Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd/remove row dynamically with drop down in it using javascript
    primarykey
    data
    text
    <p>I have project that I must make form that user can add education in it. I succeed to add and remove dynamically with (just) input in it, but I get problem when I put drop down list in it. The code is work, but I can't get any option when I click my dropdown.</p> <p>see the screenshot here: <a href="https://www.dropbox.com/s/q58ic9jvq2sqofh/Capture.JPG" rel="nofollow">https://www.dropbox.com/s/q58ic9jvq2sqofh/Capture.JPG</a></p> <p>HTML</p> <pre><code>&lt;h3&gt;Pendidikan&lt;/h3&gt; &lt;table id="pendidikan"&gt; &lt;input type="button" value="Tambah Data" onClick="addRow('pendidikan')" /&gt; &lt;input type="button" value="Hapus Data" onClick="deleteRow('pendidikan')" /&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;Jenjang&lt;/th&gt; &lt;th&gt;Nama Institusi&lt;/th&gt; &lt;th&gt;Kota&lt;/th&gt; &lt;th&gt;Tahun&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" name="chk[]"/&gt; &lt;/td&gt; &lt;td&gt; &lt;select name="jenjang[]"&gt; &lt;option value="sd"&gt;Sekolah Dasar&lt;/option&gt; &lt;option value="smp"&gt;Sekolah Menengah Pertama&lt;/option&gt; &lt;option value="sma"&gt;Sekolah Menengah Atas&lt;/option&gt; &lt;option value="d3"&gt;Perguruan Tinggi (D3)&lt;/option&gt; &lt;option value="s1"&gt;Perguruan Tinggi (D4/S1)&lt;/option&gt; &lt;option value="s2"&gt;Perguruan Tinggi (S2)&lt;/option&gt; &lt;option value="s3"&gt;Perguruan Tinggi (S3)&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="pendidikan" name="pendidikan[]"type="text" size="30" maxlength="30"/&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="pendidikanDi" name="pendidikanDi[]" style="width: 200px;" type="text" size="30" maxlength="30"/&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="pendidikanTahun" name="pendidikanTahun[]" style="width: 200px;"type="text" size="30" maxlength="30"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>Javascript</p> <pre><code>function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); var element2 = document.createElement("select"); element2.name="jenjang[]"; cell2.appendChild(element2); var cell3 = row.insertCell(2); var element3 = document.createElement("input"); element3.type = "text"; element3.name = "pendidikan[]"; cell3.appendChild(element3); var cell4 = row.insertCell(3); var element4 = document.createElement("input"); element4.type = "text"; element4.name = "pendidikanDi[]"; cell4.appendChild(element4); var cell5 = row.insertCell(4); var element5 = document.createElement("input"); element5.type = "text"; element5.name = "pendidikanTahun[]"; cell5.appendChild(element5); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i&lt;rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox &amp;&amp; true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </code></pre> <p>Thanks for your advance!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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