I have two switch statements and I need a third statement to determine one of the two to run. In the first statement(default) I have:
innerHTML = "<form><input id='rb1' type='radio' name='option1' value='1'>1<input type='radio' name='option1' value='2'>2<form>";
I'm trying to place the value in var testNumber
I've used document.getelementByNames('option1').checked and for some reason checked causes errors. iv also used document.querySelector('input[name="rate"]:checked').value; and that causes errors also
function
switch (testNumber) {
case 1:
test1();
break;
case 2:
test2();
break;
default:
test1();
break;
}
function test1() {
let div1 = document.getElementById('div1');
div1.innerHTML = "<form><input id='rb1' type='radio' name='option1' value='1'>1<input type='radio' name='option1' value='2'>2<form>";
testNumber = whatTest();
}
whatTest() {
let option1 = document.getElementsByName(option1)
for (let i = 0; i < option1.length; i++) {
if (option1[i].checked) {
return option1[i].value;
}
}
}