I want to show the content of a txt file inside a \'div\', so I\'m calling my function with a button, but the functions triggers even if I don\'t push the button, here\'s my
You are calling a function instead of passing in as a anonymous method.
window.onload=function(){
document.getElementById("showF").addEventListener("click" , function(){
sacardatos('P1.txt','container');
},false);
}
The second argument to addEventListener
should be a function. You're not passing a function, you're calling the function immediately and passing the result. Change to:
document.getElementById("showF").addEventListener("click", function() {
sacardatos('P1.txt','container');
}, false);