I have what I think should be a simple function that is returning:
TypeError: ele("XYZ") is null
and is not returning the proper value. In my case, element XYZ is called AgeCount. Here is my script:
function countAgesSelected(){
var agesSelectedCount = 0;
if (document.myform.a4049.checked==true) {
agesSelectedCount++;
}
if (document.myform.a5064.checked==true) {
agesSelectedCount++;
}
if (document.myform.a65plus.checked==true) {
agesSelectedCount++;
}
ele('AgeCount').value = agesSelectedCount;
}
Browser throws the error on that last line.
Here is relevant HTML:
<input name="4049" type="checkbox" value="4049" id="a4049" starweb_type="Checkbox/Radio Button" checked="checked" onclick="countAgesSelected()" />40-49
<input name="5064" type="checkbox" value="5064" id="a5064" starweb_type="Checkbox/Radio Button" checked="checked" onclick="countAgesSelected()" />50-64
<input name="65plus" type="checkbox" value="65plus" id="a65plus" starweb_type="Checkbox/Radio Button" checked="checked" onclick="countAgesSelected()" />65+
<input type="hidden" value="0" name="AgeCount" />
I am hoping that I just have a simple syntax error. Any help is greatly appreciated!
Update
Mixed up getElementsByName and getElementsByTagName, code is now updated.
Where is the
elefunction coming from?Use
document.getElementsByName("AgeCount")[0]instead of the ele-function or create the ele-function like this: