I have a for loop which is supposed to assign functions based on user input (binding the function to a button). Instead, no matter which button is clicked (except the cancel button) the same function runs.
The function looks like this...
Per the requests below, here's a cleaner example :
HTML
<button id="myButton">
Button 1
</button>
<button id="myButton2">
Button 2
</button>
<button id="myButton3">
Button 3
</button>
JAVASCRIPT
var myFunctions = {
myButton: function(o){ alert("Button 1 pressed! (" + o +")"); },
myButton2: function(o){ alert("Button 2 pressed! (" + o +")"); },
myButton3: function(o){ alert("Button 3 pressed! (" + o +")"); }
}
function runBinds(binds){
for(bind in binds){
var myButton = document.getElementById(bind),
myCall = function(){
binds[bind]("Appended info");
};
myButton.addEventListener('click',myCall,false);
}
}
runBinds(myFunctions);
Jsfiddle
As I mentioned before, I tried using closures and this did not resolve my issue, so it is not a duplicate.