Problems with Clearing Input FILE Text Box

P

Pavan Jha

Hi,

I am using File Input for one of my pages. I have multiple inputs on
my page as

<INPUT Type=FILE Name=File1>
<INPUT Type=FILE Name=File2>
and so on...

I have a function for validating filetype which is called on onChange
of File

<INPUT Type=FILE Name=FILE1 onchange='return
validatefiletype(document.MyForm.FILE1)'>

take a look at the code snippet below for validatefiletpye

function validateFileType(thisvalue){
var i;
var ufilename;
if (thisvalue.value.length > 0 )
{

ufilename = thisvalue.value.toUpperCase();

var extnarr = ufilename.split(".");

fileType = "." + extnarr[extnarr.length-1];

if (fileType == ".GIF")
{
thisvalue.value = thisvalue.value.toString();
return true;
}
else
{

alert("Only the GIF files are allowed for uploading");
thisvalue.value = "" ;
return false;
}

}

}


Now on to the problem..

The script runs and works fine till the alert part.. means it does
flash alert when it finds the wrong format (anything but gif) has been
chosen for upload... but it doesn't perform the next two steps of
clearing the File Text box which now shows the selected file name (of
a non supporting extension, which should be cleared as soon as it
finds its unacceptable)..

Can any one tell the reason of this behaviour and how to get it
working..

thanks

p1j
 
M

Martin Honnen

Pavan Jha wrote:

I am using File Input for one of my pages. I have multiple inputs on
my page as

<INPUT Type=FILE Name=File1>
<INPUT Type=FILE Name=File2>
and so on...

I have a function for validating filetype which is called on onChange
of File

<INPUT Type=FILE Name=FILE1 onchange='return
validatefiletype(document.MyForm.FILE1)'>
alert("Only the GIF files are allowed for uploading");
thisvalue.value = "" ;
return false;
The script runs and works fine till the alert part.. means it does
flash alert when it finds the wrong format (anything but gif) has been
chosen for upload... but it doesn't perform the next two steps of
clearing the File Text box which now shows the selected file name (of
a non supporting extension, which should be cleared as soon as it
finds its unacceptable)..

Can any one tell the reason of this behaviour and how to get it
working..

It is simple, script is not allowed to set the value of the <input
type="file"> element object as that way you could upload files from the
browser user's file system without the user selecting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top