The following error occurred while working with radiobutton: document.getElementByName is not function. How to fix it? Below is a line of code in which this error is observed. Full code below.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p> <input type="radio" name="prim" value="груши">Яблоки</p> <p> <input type="radio" name="prim" value="груши">Груши</p> </body> </html> <script> var radio = document.getElementByName('prim'); for (var i=0; i<radio.length; i++) { radio[i].onchange = testRadio; } function testRadio() { console.log (this.value); } </script>
getElementsByName, there is nogetElementByName. - Suvitruf ♦