By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,833 Members | 2,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,833 IT Pros & Developers. It's quick & easy.

Problems with Clearing Input FILE Text Box

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.