I know "getElementsByClassName
" is not support by IE8
. Do you know what can I use instead? I am getting annoying by error
"Object doesn't support this property or method".
The HTML code is:
function sumar() {
var elems = document.getElementsByClassName('verdana14 toAdd');
var myLength = elems.length;
total = 0;
for (var i = 0; i < myLength; ++i) {
if (elems[i].value!="") {
total += parseInt(elems[i].value,10);
}
}
var promedio = total/myLength;
parseFloat(document.getElementById('promediocal').value = promedio.toFixed(2));
}
This the input text that calls the javascript function:
<input name='AE_EA_1_BIV_003_2' type='text' class='verdana14 toAdd' id='AE_EA_1_BIV_003_2' style='width:50px' onChange='sumar()'/>
<input name='AE_EA_1_BIV_003_3' type='text' class='verdana14 toAdd' id='AE_EA_1_BIV_003_3' style='width:50px' onChange='sumar()'/>
<input name='AE_EA_1_BIV_003_4' type='text' class='verdana14 toAdd' id='AE_EA_1_BIV_003_4' style='width:50px' onChange='sumar()'/>
Use document.querySelectorAll('.verdana14.toAdd')
.
See also my related blog post.