QP School
Select elements by name in JavaScript - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: JavaScript Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=6)
+--- Thread: Select elements by name in JavaScript (/showthread.php?tid=4079)



Select elements by name in JavaScript - Qomplainerz - 04-04-2023

The HTML part between the <body></body> tags looks like this:

Code:
<!-- Select elements by name -->

<input type="radio" name="size" value="S"> S
<input type="radio" name="size" value="M"> M
<input type="radio" name="size" value="L"> L
<input type="radio" name="size" value="XL"> XL
<input type="radio" name="size" value="XXL"> XXL

The JavaScript part looks like this:

// Select elements by name

let elems = document.getElementsByName('size');
let sizes = [].map.call(elems, elem => elem.value);

document.write("<br>");
document.write(sizes);
document.write("<br>");