468,103 Members | 1,211 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Events for input type="file"

Hi all

I have a webpage where I want the user to input filenames. To make this easier,
I use a file input type so that the user can select files rather than typing in
the filename, using the HTML below.

<input type="file" size="25" maxlength="256" id="filename" onchange="AddFile()"
/>

The problem I have is that the javascript function AddFile() is only run under
Internet Explorer, and not under Mozilla. I need the function to run each time a
file is selected as the filenames are added to a text box (the user is creating
a list of files).

Is there some way of having this work under Mozilla?

Thanks.
Jul 23 '05 #1
2 43389
On Sun, 4 Apr 2004 01:42:25 +1200, @lias
<ki*****@yahoo.spammers.go.here.com> wrote:
I have a webpage where I want the user to input filenames. To make this
easier, I use a file input type so that the user can select files rather
than typing in the filename, using the HTML below.

<input type="file" size="25" maxlength="256" id="filename"
onchange="AddFile()" />

The problem I have is that the javascript function AddFile() is only run
under Internet Explorer, and not under Mozilla. I need the function to
run each time a file is selected as the filenames are added to a text
box (the user is creating a list of files).
The onchange event works very strangly with file-type INPUTs when the
"Browse" button is used. It doesn't fire at all in Mozilla, and the
control must lose focus for it to fire in Netscape. It fires as you expect
it to with Opera and IE. When changed via the keyboard, all of these
browsers will fire the event once the control loses focus.
Is there some way of having this work under Mozilla?


Use the onclick event in tandem with onchange. You'll have to keep a
record of the previous value though, to see if the value was indeed
changed, or if the control was simply clicked. A better alternative is to
use a separate button to call the AddFile() function.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Sun, 4 Apr 2004 01:42:25 +1200, @lias
<ki*****@yahoo.spammers.go.here.com> wrote:
I have a webpage where I want the user to input filenames. To make this
easier, I use a file input type so that the user can select files rather
than typing in the filename, using the HTML below.

<input type="file" size="25" maxlength="256" id="filename"
onchange="AddFile()" />

The problem I have is that the javascript function AddFile() is only run
under Internet Explorer, and not under Mozilla. I need the function to
run each time a file is selected as the filenames are added to a text
box (the user is creating a list of files).


The onchange event works very strangly with file-type INPUTs when the
"Browse" button is used. It doesn't fire at all in Mozilla, and the
control must lose focus for it to fire in Netscape. It fires as you expect
it to with Opera and IE. When changed via the keyboard, all of these
browsers will fire the event once the control loses focus.
Is there some way of having this work under Mozilla?


Use the onclick event in tandem with onchange. You'll have to keep a
record of the previous value though, to see if the value was indeed
changed, or if the control was simply clicked. A better alternative is to
use a separate button to call the AddFile() function.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)


Thanks for your help Michael. I guess I'll stick with adding a separate button.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jesper Hermansen | last post: by
2 posts views Thread by IkBenHet | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.