Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda