So I have some radio buttons and I am currently checking to see if they are checked and am getting the value from it find using this:
var selectedAnswer = document.querySelector('input[name="question1"]:checked').value;
This returns what I want it to but I have several different forms, each with the name question1, question2, and so forth. Is there any way I can use that querySelectory method and have name="question" + 1 each time, such that I can loop through each question in every form. If I can find out if this is legal or not I can easily accomplish it with a for loop.
I have tried this:
for (let i = 1; i <= 5; i++) {
var selectedAnswers = document.querySelector(`input[name="question${i + 1}]:checked`).value
}
Yet it the the value is returning null, meaning the interpolation is failing.