Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html input onchange doesn't accept anonymous function

Why does this not work?

 <input type="file" id="kmlFiles2" multiple onchange="function(){alert('why does this not work')}()">

chrome gives me an error, Uncaught SyntaxError: Unexpected token (.

Firefox tells me SyntaxError: function statement requires a name.

But this does work?

 <input type="file" id="kmlFiles2" multiple onchange="alert('but this does work')">

http://jsfiddle.net/ewzyV/

I am asking because I was was trying to use and MVC framework that injects code into the onchange event.

like image 250
dooderson Avatar asked Jun 05 '14 20:06

dooderson


1 Answers

onchange="(function(){alert('this should work')})()"
like image 174
aljgom Avatar answered Oct 07 '22 10:10

aljgom