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

134
Visualizações
Get values from HTML only if the checked box is checked (HTML + Python script)

I have a web page with multiple checkboxes and the relative input values enter image description here

with the following code:

<tr><td><input type=\"checkbox\" id=\"second_checkbox\" name=\"second_checkbox\" value=\"" + Sample_ID + "\"><label for=\""+ Sample_ID + "\">"+ Sample_ID +"</label><br></td><td><select name=\"option\" id=\"option\"><option value=\"\" selected=\"selected\"></option><option value=\"=\">=</option><option value=\"!=\">!=</option><option value=\">\">></option><option value=\">=\">>=</option><option value=\"<\"><</option><option value=\"<=\"><=</option><option value=\"ilike\">contains</option></select></td><td><input type=\"text\" name=\"valore\" placeholder=\"value\"></td></tr>"

and I get the different values by using this functions:

filtri = request.form.getlist('second_checkbox')
simbolo = request.form.getlist('option')
valori = request.form.getlist('valore')

but the array "valori" takes all the empty values on the page and I want to take only the ones that are checked on the first checkbox. How can I do that?

Thanks

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

0

First, remove the duplicate id's and names in the html. An id in html should be unique. Using the right selection mechanism you don't need them either.

For the client side (so, within the browser) you can select all checked checkboxes using the selector [type=checkbox]:checked. Here's a minimal reproducable example.

document.addEventListener(`click`, evt => {
  console.clear();
  const allChecked = document.querySelectorAll(`[type='checkbox']:checked`);
  //                                                             ^ only checked
  if (allChecked.length) {
    return allChecked
      .forEach(cb => {
        const theRow = cb.closest(`tr`);
        console.log(`checked row (#${theRow.rowIndex + 1}) text input value: ${
          theRow.querySelector(`input[type='text']`).value || `no value`}`);
      });
  }
  return console.log(`none checked (yet)`);
});
<table>
  <tr>
    <td>
      <input type="checkbox" value="123"> 123
    </td>
    <td>
      selector here
    </td>
    <td>
      <input type="text" placeholder="value" value="row 1">
    </td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="456"> 456
    </td>
    <td>
      selector here
    </td>
    <td>
      <input type="text" placeholder="value" value="row 2">
    </td>
  </tr>
  <tr>
    <td><input type="checkbox" value="789"> 789
      <td>
        selector here
      </td>
      <td>
        <input type="text" placeholder="value" value="row 3">
      </td>
  </tr>
</table>

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