I want to add an event listener to input elements with element id's I have stored in a list and then take the product of them. For example:
a = ['id1', 'id2', 'id3']
I would like to do something like:
input element id1 = 0.5
input element id2 = 0.6
input element id3 = 1.0
return 0.5*0.6*1
and I would like this to update as the user changes the values in the input box.
So I have started with something like:
function calcProduct(values){
var product = 1;
for(i=0; values.length; i++){
product = product*values[i];
}
return product
}
id_list = ['id1', 'id2', 'id3']
function calcProduct(id_list){
for(i=0; id_list.length; i++){
//how do I get the values as they change so I can feed it to calcProduct?
document.getElementById(id_list[i]).addEventListener("onchange", calcProduct(values) )
}
}