I’m working on a form with radio input that has values “yes” and “no”.
Here’s the code:
<input type="radio" id="haveread" name="check" value="yes"><label for='haveread' >Yes</label>
<input type="radio" id="notread" name="check" value="no"><label for="notread" >No</label>
I’d like to retrieve the radio input value of the radio that has been checked and assign it to variable called readStatus
Here’s my code:
const readStatus = document.querySelector('input[type="radio"]:checked');
I tried checking the variable readStatus on my console.log and it returns null.
However, when i input document.querySelector(‘input[type=”radio”]:checked’ on the console.log, which is the content of the variable readStatus, i get what I’m looking for which is the checked radio input.
i am expecting the variable readStatus to also return the checked radio input. I’m very confused as to how this works because I’m basically console.logging the same thing.
Can anyone tell me what I’m doing wrong ?
1