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

202
Views
Radio button value for switch statement's expression

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;
    }
  }
}
about 4 years ago · Juan Pablo Isaza
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!