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

214
Views
JavaScript How to check if radiobutton is checked or not?

I'm going to put on my website simple radiobutton. His role is only to have value 'on' if checked or 'off' if not checked.

home.html

<input type="radio" id="radio1" class='radio-button' value="off">
<label >Radio1</label>
<br>
<input type="radio" id="radio2" class='radio-button' value="off">
<label >Radio2</label>

I wrote a loop in my js file code to iterate through the inputs and my goal is to change value to 'on' if checked.

myJs.js

const radioButtons = document.getElementsByClassName('radio-button')
for (let radio of radioButtons){if (radio.checked){ radio.value='on'}

But it doesn't work. Value stays 'off' even if radiobutoon is checked. Any idea what am I doing wrong?

about 4 years ago · Santiago Gelvez
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!