Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
I can't get the id of the selected item via checkbox with IE

I'm having trouble retrieving the id of the selected objects via checkbox.

I have not put all the code because it is too long, I have only entered what is needed.

allart.Items.forEach(function (item) {               
                    let child = document.createElement("tr");
                    child.innerHTML =
                        '<td>' + item.id + '</td><td>' + item.title + '</td><td>' + item.date + '</td><td><input type="checkbox" id="myCheck" data-item-id=+item.id+></td>';
                    table.appendChild(child);

<table id="my-table" width="90%">
        <tr>
            <th>Id</th>
            <th>Title</th>
            <th>Date</th>
            <th>Selection</th>
        </tr>

    </table>

    <br><br>

        <input type="button" value="GetID" onclick="getId" />

function getId() {
            var cbs = document.querySelectorAll('#my-table input[type="checkbox"]:checked');
            console.log(cbs.length);
            const ids = Array.from(cbs).map(function (cb) { cb.getAttribute("data-item-id") });
            console.log(ids);
            for (let i = 0; i < ids.length; i++) {
                deleteRow(ids[i]);
            }
        }

I can't get the ids variable.

ids return length 1 but data-item-id is undefined.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just change your const ids declaration to the following:

            ids = []
            cbs.forEach((checkedBox) => {
                ids.push(checkedBox.getAttribute("data-item-id"))
            })

(Fiddle here: https://jsfiddle.net/3madc64u/1/)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda