Usually we will be creating many validation scripts for validating input elements
Consider a situation where we need to allow user to upload only specific file type or specific sized files
then we may have to write a javascript through which we have to cancel upload from javascript
i.e., to clear the value in the file box but unless like other html input controls the property value is readonly on some browsers for file box hence we can’t clear it.
Let’s follow the simple steps to clear it through javascript
Sample is here for you
Works in Netscape browsers Only
Works in All Browsers
Consider a situation where we need to allow user to upload only specific file type or specific sized files
then we may have to write a javascript through which we have to cancel upload from javascript
i.e., to clear the value in the file box but unless like other html input controls the property value is readonly on some browsers for file box hence we can’t clear it.
Let’s follow the simple steps to clear it through javascript
- Enclose the file input box with either div/table/span and assign an id for enclosed component
- Now just add a method/function to attribute onchange for the file control
- Just write the validation script over that function. once validated we have to invoke a function to clear whose contents are
var ee=document.getElementById("enclosedElementID"); var filebox=document.getElementById("fileElementID"); var filevalue=filebox.value; var fileInputRegEx=new RegExp(filevalue,"g"); ee.innerHTML=ee.innerHTML.replace(sRegExInput,"");
Sample is here for you
Works in Netscape browsers Only
Works in All Browsers