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?