Forum Moderators: open

Message Too Old, No Replies

file.click() do not work

         

Xuefer

3:13 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



code:

<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="button" onclick="document.getElementById('file').click()" value="click me">
<input type="submit" value="Submit">
</form>

click button to select a file, it's ok.
but press Submit will clear file input, no submit
must press again will submit, but no file uploaded

almost same problem as [experts-exchange.com...]
but i need the real file uploaded

system: winxp sp2
browser: ie6 (come with sp2)
gmail js: works
my code: failed :(

any idea?

iamlost

12:00 am on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you not need action="<HTTP URI>"?

I believe it is a required attribute.

[url]http://www.w3.org/TR/REC-html40/interact/forms.html[/url

Xuefer

3:04 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



that was just an example

here we go:

<form method="post" enctype="multipart/form-data" action="about:blank" onsubmit="alert(this.elements.file.value); return true">

u can try action="abc.php" for testing
all with same result

Xuefer

7:20 am on Nov 20, 2004 (gmt 0)

10+ Year Member



shall this thread move to javascript?

Xuefer

3:16 pm on Nov 30, 2004 (gmt 0)

10+ Year Member



it's denied for security, but i finally get it works on xpsp2

** just need cross frame **
file.click() must be done in another frame excluding the on "file" is in

should be IE security hole?
but gmail did so. and no check for failure.
doing .click() will not cause error, but after selected file, and access file.value, will cause.
i'd guess gmail's _CM_OnAttach() can catch and report the error, but wonder what gmail will do when ie suddently fix this hole.

my auto update installed the lastest hotfix for ie today, but still don't have this fixed

xrom2

2:27 pm on Jan 9, 2005 (gmt 0)



Xuefer you're great!

this trick (althought is a little dirty)
resolve problems styling the input file!

thanks so much.

orion_rus

3:12 pm on Jan 9, 2005 (gmt 0)

10+ Year Member



))))
function document.getElementById resolves only id's not name))
u should type id='file' not name)
good luck to you)

Xuefer

3:18 pm on Jan 9, 2005 (gmt 0)

10+ Year Member



my bad, you're right
but IE will give u surprise: i can select file :P

by adding id="file" gives no help
<input type="file" name="file" id="file">

orion_rus

11:06 am on Jan 10, 2005 (gmt 0)

10+ Year Member



U can select file, or u can't select it?))
if u can it seem to alright)

Xuefer

12:53 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



my first post:
==
click button to select a file, it's ok.
but press Submit will clear file input, no submit
==

did u read it carefully?

orion_rus

3:33 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



but u need action in form to a script page? can u show it? of cause it wouldn't send anythere if u don't make action command. if u need to place it to this script, type address of this script in the action field, but it's necessary
Good luck to you

Xuefer

4:10 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



that's not the problem

u don't see the problem may because u don't have xpSP2 or u havn't tried

i know what i'm doing, i know how to get file uploaded without onclick javascript

u may try it with action="#*$!.php"
maybe u can find me a better workround to the problem

but whatever, thanks for your carefulness