Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Multiselect dropdown not working for dynamic html table creation in Jquery

I am working on creating a table in asp.net MVC and having a button at the end for adding the rows. below is the code for adding rows. In this table we have only dropdowns and 1 multiselect dropdown for which I am using the boot strap multiselect js and css files.

For the 1st row I am able to select but for the second row the multiselect is not working like when select all is clicked its not getting selected or when one value is checked its not getting highlighted.

Please let me know if any leads.

function addRows() {

            var table = document.getElementById('totaltbl');
            var rowCount = table.rows.length;
            if (rowCount == 1)
            {
                location.reload();
                return false;
            }
            var cellCount = table.rows[0].cells.length;
            var row = table.insertRow(rowCount);
            for (var m = 0; m < rowCount; m++) {
                row.setAttribute("id", "col" + m);
            }
            for (var i = 0; i <cellCount -1; i++) {
                var cell = 'cell' + i;
                cell = row.insertCell(i);
                if (i == 1) {
              
                //This cell contains the multiselect dropdown. Copying the first cell as it is and changing the id of the multiselect dropdown
                    var copycel = document.getElementById('col' + i).innerHTML;
                    cell.innerHTML = copycel;
              
                   var id= $('table td:eq(3) select').attr('id')
                    cell.setattribute("id", "customertype" + i)
                    var element = $('table tr #col' + i +'  select')
                    element.attr('id', 'customertype' + i);
                   
                 
                   var rowid = row.id
                   var Ids = rowid.replace(/\D/g, "")
  
                 
               // each row as a customertype to differentiate that we create the id and add to the CustomerType Id
                   $('#CustomerType' +Ids).multiselect();
                   $('#'+custid).multiselect({
                       includeSelectAllOption: true
                    });
                      

                }
                else {
                    var copycel = document.getElementById('col' + i).innerHTML;
                    cell.innerHTML = copycel;
                }
               
            }
           
        }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!