 <p>The second argument to <code>addEventListener</code> should be a function. You're not passing a function, you're calling the function immediately and passing the result. Change to:</p> <pre><code>document.getElementById("showF").addEventListener("click", function() { sacardatos('P1.txt','container'); }, false); </code></pre>