There are several input radio , but only one checked , that's what you need to access it using Javascript.
In general, an analogue of the Jquery function is needed:

$(".item:radio:checked").click(); 
  • Than $("radio:checked").click(); not satisfied? - Andrew B
  • It would suit me, but the Javascript language is used, so I need an equivalent in Javascript. - Eugene

1 answer 1

There is such a thing as Document.querySelector () - returns the first element inside the document (using a pre-ordered depth traversal of nodes to the first found node) that matches a certain group of selectors.

Syntax

 element = document.querySelector(selectors); 

Where

element is an element object.
selectors - a string containing one or more CSS selectors, separated by a comma

 var checkedRadio = document.querySelector('input[name="rate"]:checked'); console.log(checkedRadio); console.log(checkedRadio.value); 
 <div id="rates"> <input type="radio" id="r1" name="rate" value="Fixed Rate"> Fixed Rate <input type="radio" id="r2" name="rate" value="Variable Rate"> Variable Rate <input type="radio" id="r3" name="rate" value="Multi Rate" checked="checked"> Multi Rate </div> 

another option

 var radios = document.getElementsByName('genderS'); for (var i = 0, length = radios.length; i < length; i++) { if (radios[i].checked) { console.log(radios[i].value); break; } } 
 <input type="radio" name="genderS" value="male" checked>Male <input type="radio" name="genderS" value="female">Female 

  • Alex, thank you! The first option is what you need! - Eugene