I'm trying to write a script that can be run against any site, so i dont want to use any inline onchange approach. The script should fire any time there is a change to the inputCollection being created.
When I run the snippet below, I get an instant iteration and output of ALL the input fields and their value. But on "change" nothing happens.
So two issues: 1. I want it to only output the input that changed. 2. I want it to only run on the "change" event
Any insights in to what I'm doing wrong here? Here is a fiddle. http://jsfiddle.net/owq4n2eg/
(function () {
var inputCollection = document.getElementsByTagName("input");
for(var i=0;i<inputCollection.length;i++)
{
inputCollection[i].addEventListener("change",console.log("name:" + inputCollection[i].name + ",value:"+inputCollection[i].value),false);
};
})();
Thanks!