Skip to content Skip to sidebar Skip to footer

How To Make A File Upload Field Empty In Struts2 Using Javascript?

I have a file upload field,that is,. And I have a button 'clear'. On clicking this button, the field which has some file link should become empty.Coul

Solution 1:

Assuming

<inputtype="button" onclick="clearFileElement('filetestplanid2');" />

Vanilla JS

functionclearFileElement(fileId){
    document.getElementById(fileId).value = '';
};

Demo: http://jsfiddle.net/2nxGr/

Can't make it works with jQuery but basically you have to substitute it with a clone of itself (with all the properties, gained using clone(true)).

Just stick to the plain JS version, it works like a charm.

EDIT

I've found now a very smart solution that works on every browser: https://stackoverflow.com/a/13351234/1654265

Solution 2:

You can make it empty using Jquery too, just like this:

$("#filetestplanid2")[0].value = ""

or

$("#filetestplanid2").get(0).value = ""

Post a Comment for "How To Make A File Upload Field Empty In Struts2 Using Javascript?"