I've encountered an issue even after adding an id in HTML for JS. Upon opening the website, I see the following error:
Uncaught TypeError: Cannot set property 'onclick' of null
Your assistance is greatly appreciated.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="jquery-1.7.2.js" type="text/javascript"></script>
<script>
var btn = document.getElementById("btn");
btn.onclick = function() {
var arrays = new Array();
var items = document.getElementsByName("check");
for(var i=0;i<items.length;i++) {
if(items[i].checked) {
arrays.push(items[i].value);`enter code here`
}
}
alert("numbers checked:" + arrays.length);
}
</script>
</head>
<body>
<input type="checkbox" value="1" name="check" checked/>
<input type="checkbox" value="2" name="check"/>
<input type="checkbox" value="3" name="check" checked/>
<input type="button" value="numbers you have checked" id="btn"/>
</body>
</html>