<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> JavaScript DOM getElementsByName() Method </title>
</head>
<body>
Samsung: <input name="Smartphone" type="checkbox" value="Samsung">
OnePlus: <input name="Smartphone" type="checkbox" value="OnePlus">
<p>Click the button to check all checkboxes that have a name attribute with the value "Smartphone".</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.getElementsByName("Smartphone");
var i;
for (i = 0; i < x.length; i++) {
if (x[i].type == "checkbox") {
x[i].checked = true;
}
}
}
</script>
</body>
</html>