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

129
Views
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 answers
Answer question

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 Report
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!