472,795 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

onChange in <input type="file"...>

I'm trying to handle the onChange event in an <input type="file">
element. In IE, there's no problem: the event fires when a file in the
"open" box is doubleclicked, or the "Open" button in the box is
clicked, or "Enter" is hit in the attached text box. I can get the
value of the element.

But in Netscape 7, onChange doesn't fire until focus leaves the
element. When you double-click a file name or click "open" in the Open
box, the filename appears in the text box, but nothing happens. When
focus leaves the text box, the event fires, but the "value" attribute
of the item has NO VALUE!!!

I wish I could tell you what Firefox does, but we're not allowed to
use Firefox here (even though we're making web systems for the general
public to use!! Don't get me started....)

So what do I have to do to properly catch this event in Gecko
browsers?

--
Tim Slattery
Sl********@bls.gov
http://members.cox.net/slatteryt
May 31 '07 #1
7 20769
Hi Tim,

If I remember correctly, you are getting the correct bihaviour with
Netscape. IE is screwing up.
onChange applies when focus is lost and value is changed.

There is a way you can simulate it using onBlur and checking is value !
= '';
May 31 '07 #2
Tim Slattery said the following on 5/31/2007 2:19 PM:
I'm trying to handle the onChange event in an <input type="file">
element. In IE, there's no problem: the event fires when a file in the
"open" box is doubleclicked, or the "Open" button in the box is
clicked, or "Enter" is hit in the attached text box. I can get the
value of the element.

But in Netscape 7, onChange doesn't fire until focus leaves the
element.
What version of NS7? In NS 7.2 it fires the onchange as soon as I choose
a file and dismiss the file dialog box.
When you double-click a file name or click "open" in the Open
box, the filename appears in the text box, but nothing happens. When
focus leaves the text box, the event fires, but the "value" attribute
of the item has NO VALUE!!!
I can't reproduce that behavior. It my be a version of NS7 that doesn't
allow the reading of file input values by script for some obscure NS/AOL
reason. I tested it both locally and on a live server and get the same
results - I get the value. That leads to thinking something else in your
code is causing NS7 to bonkers out on you.
I wish I could tell you what Firefox does, but we're not allowed to
use Firefox here (even though we're making web systems for the general
public to use!! Don't get me started....)
<input type="file" onchange="alert(this.value)">

IE7, Opera9, NS8, NS7.2, FF1.5 and FF2.0 all behave the same for me.
They all alert the file name as soon as the File Dialog window is
dismissed and the value of the input has been set.

The only difference I see in what is being alerted is whether it gives
the full path to the file or not. FF, NS and IE give me full paths.
Opera gives me just the file name. Whether IE7 gives the full path or
just the file name is a user setting though.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 31 '07 #3
Hi Tim,

If I remember correctly, you are getting the correct bihaviour with
Netscape. IE is screwing up.
onChange applies when focus is lost.
May 31 '07 #4
no*************@gmail.com said the following on 5/31/2007 6:30 PM:
Hi Tim,
This is not email, so I am not Tim. Please quote what you are replying to.
If I remember correctly, you are getting the correct bihaviour with
Netscape. IE is screwing up.
IE doesn't fire the onchange when the element is set, it is firing it
after it has changed and clicking in the File Dialog box is causing the
input to lose focus (an alert does the same thing).
onChange applies when focus is lost.
Nobody said any differently.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 31 '07 #5
You can setup an interval with the onclick of "browse" input. In your
interval simply check for the value of the "browse" input value.
On May 31, 3:35 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
noagbodjivic...@gmail.com said the following on 5/31/2007 6:30 PM:
Hi Tim,

This is not email, so I am not Tim. Please quote what you are replying to.
If I remember correctly, you are getting the correct bihaviour with
Netscape. IE is screwing up.

IE doesn't fire the onchange when the element is set, it is firing it
after it has changed and clicking in the File Dialog box is causing the
input to lose focus (an alert does the same thing).
onChange applies when focus is lost.

Nobody said any differently.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Jun 1 '07 #6
Randy Webb <Hi************@aol.comwrote:

>I can't reproduce that behavior. It my be a version of NS7 that doesn't
allow the reading of file input values by script for some obscure NS/AOL
reason. I tested it both locally and on a live server and get the same
results - I get the value. That leads to thinking something else in your
code is causing NS7 to bonkers out on you.
Geez...this morning I can't reproduce it either. It still doesn't fire
in NS (7.02, by the way) until focus goes someplace else, but then it
seems to work properly. I kind of understand that, but it's
inconvenient.

I'm using a nifty Javascript from www.the-stickman.com (it was
mentioned in this group at one time), that allows selecting multiple
files in an HTML page. When the user uses and assigns a value to an
<input type="file" ...element, the onchange handler hides that
element and creates a new one. It also adds a line to a list of
selected files elsewhere on the page. So, although you can select only
one at a time, you can do that over and over to get as many as you
want.

This is working fine in IE. All the hidden <input type="file"...>
elements result in files being sent to the server. In NS7.02, for some
reason, all the hidden <input type="file"...elements have no value
and nothing gets sent to the server. (Verified by looping through all
these elements when the form is submitted, and using "alert" to show
their value.)

So I made a little, simple test case and got the bogus results I
reported earlier.

The hiding is actually done by moving the element way off the left
edge of the page (this.style.left="-1000px";). The comment at that
point says it doesn't use display:none because Safari doesn't like it.

But I can't figure out why the elements lose their value in NS. Maybe
it's a bug that's been fixed since.

--
Tim Slattery
Sl********@bls.gov
http://members.cox.net/slatteryt
Jun 1 '07 #7
Tim Slattery said the following on 6/1/2007 10:30 AM:
Randy Webb <Hi************@aol.comwrote:
<snip>
The hiding is actually done by moving the element way off the left
edge of the page (this.style.left="-1000px";). The comment at that
point says it doesn't use display:none because Safari doesn't like it.

But I can't figure out why the elements lose their value in NS. Maybe
it's a bug that's been fixed since.
Try leaving them visibly on the page and see if NS will retain the
values. If it does, then you know where to start looking for it. NS may
not like you moving File Controls off the screen and for some bonkers
reason it resets the value.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 2 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jesper Hermansen | last post by:
Hi! I'm making a system that will generate Winamp-playlists. To make it easy for the user to add a file to the list, I'm using <input type="file">. The problem with this is that I only get...
1
by: Ron Brennan | last post by:
I've spent all morning on this and now think there is a (slight?) possiblity that onchange doesn't work for input type="file". Can anybody shed any light on this. The onblur fires just fine. The...
2
by: Laermans_k | last post by:
Hi, Does anyone have a solution to use the <input type="file" id="filechooser"> and the <input type="submit" id="submitbutton"> in 1 button click? I've already tried to create a javascript...
1
by: Mark Sandfox | last post by:
Is there a way to restrict the user to only selecting and sending either a ..gif or .jpg. Everything I have read says this option can not be done by design (security reasons). I find that irronic...
4
by: acord | last post by:
Hi, I want to change the name of Browse to Add... How can I modify the followoing html code? <form name="iform" action="" method="post" enctype="multipart/form-data"> <input id="file"...
2
by: Tarkeshwar | last post by:
Hi All, I want to restrict the user from being entering the value in <input type="file">. It works fine in IE but not in Mozilla. I am sending my code also which works in IE and not in Mozilla.Can...
3
by: eeeeman | last post by:
This one has really got me! Im trying to write a value to a input type="file" form element using client-side javascript. I have tried the obvious, simply writing: <input type="file" ...
1
by: ChollaPete | last post by:
This code: <form action="processScan.php" method="get"> <p> <?php print "Scan name: <input type=\"file\" name=\"tScanFileName\" value= \"{$scanFileName}\"><br>"; addHiddenCarryons(); ?>...
1
by: sandeep kumar shah | last post by:
Hi, We have used a file uploading HTML tag in an HTML page. We need to customize the text displayed on the Button (which is by default “Browse…” for internet explorer). Below is the...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.