javascript based tag ( type ='file'
) created
and add one attribute in that tag
that attribute name onchange
, i will assign alert
But alert is not come when choice the new file in internet explore.
choicefile.setAttribute("onChange", "alert('test')");
You can do two ways,
1.. Using HTML, add onchange
event inline
<input type="file" id="file_select" name="file_select" value="" onchange="alert('File selected')" />
Demo: http://jsfiddle.net/CS3xJ/1/
2.. Using JS,
choicefile.onchange = function(){
alert('File selected')
}
Demo: http://jsfiddle.net/CS3xJ/2/
There is actually a difference between setAttribute
and attachEvent
. Here is an example using attachEvent
(for IE) and addEventListener
(standards) to add the event.
Also, not that the event handler is a function, rather than a string:
var eventHandler = function () {
alert("Test");
}
if (choicefile.addEventListener) {
choicefile.addEventListener('change', eventHandler , false);
} else if (choicefile.attachEvent) {
choicefile.attachEvent('onchange', eventHandler );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With