Click to See Complete Forum and Search --> : onClick action for a file form


deltareum
06-05-2003, 08:52 PM
I need to run a function any time the user makes a file selection on a file form (input type file). Placing an onClick event in the input tag causes the function to run as soon as the user clicks on the Browse button, before a file selection is made. Placing an onChange event on the input tag doesn't work. So, how do I do it?

Thanks.

Deltareum

Khalid Ali
06-05-2003, 09:11 PM
you can use file buttons onclick event..

deltareum
06-05-2003, 09:13 PM
Khalid:

You mean like: <input type="file" onCLick="run()">

??

This causes run() to run as soon as BROWSE is clicked. I want to run it as soon as a file is determined.

Khalid Ali
06-05-2003, 09:27 PM
In that case file button has another event "onchange" this should only be triggered when the file name is selected and its being viewed in the file buttons text field.

<input type="File" onchange="alert(this.value)"></input>

[b]Edit[/]
Oh BTW
File element triggers wrong events in Mozilla based browsers,hence it will not show desired results...there might be some other hacks to get the same results.in Mozilla based browsers.

(Its a known bug in Mozilla's db - bug 4033)

Charles
06-06-2003, 05:17 AM
Considering that the number of users of Mozilla is statistically insignificant and that the number of good folks that do not use JavaScript at all is 13%, I wouldn't worry about it or perhaps I'd prepend an if (navigator.appName != 'Mozilla') to the script. Just make sure the page works alright without JavaScript.

sneakyimp
03-03-2004, 08:58 PM
i'm interested in this too...i want to let users upload image files to my website...i want the image from their hard drive to be displayed in the form before they click OK to upload it. i am not very knowledgeable about the difference between mac and windows style path references and was wondering if anybody had a recommendation about how to go about this?