Events for input type="file"

@

@lias

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.
 
M

Michael Winter

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
 
@

@lias

Michael Winter said:
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.


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

Thanks for your help Michael. I guess I'll stick with adding a separate button.
 

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,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top