473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problems with Clearing Input FILE Text Box

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
1 2049


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
4
by: Ali | last post by:
I used to clear my page's control in Visual Studio 2003 using code like this: Dim c As Control For Each c In Page.Controls(1).Controls If TypeOf c Is TextBox Then CType(c, TextBox).Text = Nothing...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
1
by: Gary Wessle | last post by:
hi I have a design problem with this code, it is suppose to take a space delimited data file file_info x( f ); //f is a text file provided below and return the column of choice vector<stringbb...
1
by: RDizzle | last post by:
okay. so all i am doing is changing a registration script that uses $_GET to a script that uses $_POST, but the validation script now returns NULL values for all posted vars. What's the deal? ...
2
by: listerofsmeg01 | last post by:
I have the following code to align some form controls: <style type="text/css"> ..label {float:left; width:50%} ..input {width:40%} </style> <div> <div class="label">Enter your username:</div>...
6
by: fpcreator2000 | last post by:
Hello everyone. I'm having problems with a page I've created that is used to insert data into a database. It uploads two files into two distinct folder, and it takes the filenames and inserts...
24
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the...
0
by: clumsy_ninja | last post by:
I'm trying to create a tableless layout for a form. The following markup works as intended in Firefox and Opera, but one of IE 7's bugs ends up misplacing the floated input fields side-by-side even...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.