dropdown list not working after cloning
- I have the following code for cloning the cascading dropdownlist...it is working when the page is loading ...but after adding a dynamic row the dropdownlist in the newly added row is not working...Please help me...
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <table border="1" id="table">
- <tr><td>
- <select id="cat">
- <option value="c">A</option>
- <option value="p">B</option>
- <option value="n">C</option>
- <option value="k">D</option>
- </select>
- </td>
- <td><select id="item"></select></td>
- </tr>
- </table>
- <INPUT type='button' value='Add Row' onclick="addRow('table')" />
-
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
- <script type="text/javascript">
- c=new Array('a1','a2','a3');
- p=new Array('p1','p2','p3');
- n=new Array('n1','n2','n3');
- k=new Array('k1','k2','k3');
- populateSelect();
-
- $(function() {
- $('#cat').change(function(){
- populateSelect();
- });
- });
-
- function populateSelect(){
- cat=$('#cat').val();
- $('#item').html('');
- eval(cat).forEach(function(t) {
- $('#item').append('<option>'+t+'</option>');
- });
- }
- </script>
- <script type="text/javascript">
-
- function addRow(tableID)
- {
- //return false; // Prevent page refresh
- var table = document.getElementById(tableID);
- var rowCount = table.rows.length;
- var row = table.insertRow(rowCount);
- var colCount = table.rows[0].cells.length;
- for(var i=0; i<colCount; i++) {
- var newcell = row.insertCell(i);
- newcell.innerHTML = table.rows[0].cells[i].innerHTML;
- //alert(newcell.childNodes);
- switch(newcell.childNodes[0].type) {
- case 'text':
- newcell.childNodes[0].value = '';
- break;
- case 'checkbox':
- newcell.childNodes[0].checked = false;
- break;
- case 'select-one':
- newcell.childNodes[0].selectedIndex = 0;
- break;
- }
- }
- var frm = document.getElementsByName('leave');
- //frm.submit(); // Submit
- frm.reset(); // Reset
- }
- </script>
-
- </body>
- </html>