Forum Moderators: open

Message Too Old, No Replies

Question about onClick in a file input tag

         

quasi

8:53 pm on Apr 29, 2009 (gmt 0)

10+ Year Member



I'm currently working through some previously written html and php code.

In a form there there is the following:

<input type="file" name="f_add[]" size="40" onClick='javascript:parse_file(value);'/>

The javascript just does some parsing of the file name and populates some hidden fields.
Something that I noticed is that on some browsers the javascript is run before a file has been selected (immediately upon hitting the browse button) causing the upload to fail because the hidden fields are needed.

I was wondering if this is coded incorrectly or if this is just a browser issue.

quasi

4:07 pm on Apr 30, 2009 (gmt 0)

10+ Year Member



I see the issue now. The script works correctly only if the browse button is hit again after a file is selected. Is there a way around this like having the script run after the file is selected from the menu?

rocknbil

2:09 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The file input element is a special critter, browsers are a bit protective of what you can do with it due to security issues. Did you try changing onClick to onChange? Or possibly onBlur()?

quasi

2:56 pm on May 4, 2009 (gmt 0)

10+ Year Member



Looks like onChange did the trick. Thanks.

Funny, the only computer in the office I've found that worked with onClick in that spot happened to be used by the only person that usually uses that feature. So this slipped through the cracks for a few years.

Thanks again.