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

105
Views
Check if input is selected

HTML:

<div class="radio" id="uniform-L1"><span><input type="radio" name="length" class="radio" value="L1" id="L1"></span></div>

JS:

<script>
if(document.getElementById('L1').checked) {
         console.log("chwer");
        }
 </script>

I tried to find what's wrong with my JS but I couldn't. I have no console errors.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Listen for the change event if you want to log "chwer" everytime the radio button is checked:

document.getElementById('L1').addEventListener('change', function() {
  if (this.checked) {
    console.log("chwer");
  }
})
<div class="radio" id="uniform-L1"><span><input type="radio" name="length" class="radio" value="L1" id="L1"></span></div>

about 4 years ago · Juan Pablo Isaza Report

0

Select the node with querySelector

function checkSelection() {
    const input = document.querySelector('input[name="length"]');
    if (input.checked) {
        console.log(input.value);
    }
}
<div class="radio" id="uniform-L1">
    <input type="radio" name="length" class="radio" value="L1" id="L1"> Radio
</div>
<button onclick="checkSelection()">Check</button>

about 4 years ago · Juan Pablo Isaza Report

0

I believe the issue is that when your run your JS that would only check to see if the radio button is checked when it loads(which wouldn't be checked). If you want the JS to activate when the radio button changed you'll have to activate an onclick to check when your button has changed and then run the script.

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!