How to use HTML5 File API with Unobtrusive JavaScript? -


i use html5 file api unobtrusive javascript. can working calling javascript functions html. there way use file api unobtrusive javascript?

the file api not supported browsers, have tried in google chrome , in firefox.

from documentation works:

<input type="file" id="input" onchange="handlefiles(this.files)"> 

and have tried unobtrusive javascript doesn't work:

window.onload = function() {     var input2 = document.getelementbyid('input2');     input2.addeventlistener('onchange', handlefiles); } 

a complete example below, , testable on jsfiddle.

<!doctype html> <html> <head> <meta charset="utf-8"/> <script> window.onload = function() {     var input2 = document.getelementbyid('input2');     input2.addeventlistener('onchange', handlefiles); }  function handlefiles(e) {     alert('got files'); } </script> </head> <body> <h1>test</h1> <input type="file" id="input1" onchange="handlefiles(this.files)"/> <input type="file" id="input2"/> </body> </html> 

try:

window.onload = function() {     var input2 = document.getelementbyid('input2');     input2.addeventlistener('change', handlefiles,false);     //                       ^not onchange        ^older firefox needs } 

jsfiddle here


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -