469,890 Members | 2,319 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Designing file upload in FF

Hi folks!

Could anybody explain why does the following code :

<form name="upload" method="post">
<input type="file" name="file_1" style="display:none" />
<input type="text" name="text_1" />
<a
href="javascript:document.forms['upload'].elements['file_1'].click();">
Open
</a>
</form>

open the file dialog for selecting a file for upload in the Internet
Explorer, whereas in the FF 2.0 does not?

Regards
Victor

Nov 24 '06 #1
7 1682
ASM
Victor a écrit :
Hi folks!

Could anybody explain why does the following code :
That doesn't work with my :
- Firefox 2
- Opera 9

Seems to work wih Safari 1.3.2

--
Stephane Moriaux and his (less) old Mac already out of date
Nov 24 '06 #2
Well, but what is the reason?

ASM schrieb:
Victor a écrit :
Hi folks!

Could anybody explain why does the following code :

That doesn't work with my :
- Firefox 2
- Opera 9

Seems to work wih Safari 1.3.2

--
Stephane Moriaux and his (less) old Mac already out of date
Nov 24 '06 #3
Victor said the following on 11/24/2006 4:58 PM:
Hi folks!

Could anybody explain why does the following code :

<form name="upload" method="post">
<input type="file" name="file_1" style="display:none" />
<input type="text" name="text_1" />
<a
href="javascript:document.forms['upload'].elements['file_1'].click();">
Open
</a>
</form>

open the file dialog for selecting a file for upload in the Internet
Explorer, whereas in the FF 2.0 does not?
Because FF doesn't support the programmatic clicking of a file input
element.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 25 '06 #4

Randy Webb wrote:
<a
href="javascript:document.forms['upload'].elements['file_1'].click();">
Because FF doesn't support the programmatic clicking of a file input
element.
This is true, but additionally, Firefox doesn't support the click()
method on any DOM object, at all. You have to roll your own:

function generateClick(element) {
var clickevent=document.createEvent("MouseEvents")
clickevent.initEvent("click", true, true)
element.dispatchEvent(myevent)
}

However, even this won't work on the File input element. As far as
scripting is concerned, it's basically read-only - you can't "make" it
do anything. Which is a good thing.

David

Nov 25 '06 #5
Well, this good idea may have a good intention at its origin. But
consider the following :

I am developing a project, where there no buttons at all - it was the
wish of my customer. There are many dozens of elements for interacting
with the user, all of them uniformly designed - but for the single
place where an ugly system button would appear, with different look on
every other machine. Even worse, the project is multilingual where the
user must have possibility to switch the language of the entire site -
but for an ugly button stubbornly displaying always the same caption in
the language of the particular operating system...

AFAIK, it is not possible to provide any style for this wayward button,
isn't it?

Thus, the basic idea may have been very good intended. Known however,
that the way to the hell is paved with good intentions.

Any good intended advice for my situation would be highly appreciated.

Victor

David Golightly schrieb:
Randy Webb wrote:
<a
href="javascript:document.forms['upload'].elements['file_1'].click();">
Because FF doesn't support the programmatic clicking of a file input
element.

This is true, but additionally, Firefox doesn't support the click()
method on any DOM object, at all. You have to roll your own:

function generateClick(element) {
var clickevent=document.createEvent("MouseEvents")
clickevent.initEvent("click", true, true)
element.dispatchEvent(myevent)
}

However, even this won't work on the File input element. As far as
scripting is concerned, it's basically read-only - you can't "make" it
do anything. Which is a good thing.

David
Nov 25 '06 #6

Victor wrote:
I am developing a project, where there no buttons at all - it was the
wish of my customer. There are many dozens of elements for interacting
with the user, all of them uniformly designed - but for the single
place where an ugly system button would appear, with different look on
every other machine. Even worse, the project is multilingual where the
user must have possibility to switch the language of the entire site -
but for an ugly button stubbornly displaying always the same caption in
the language of the particular operating system...

AFAIK, it is not possible to provide any style for this wayward button,
isn't it?
Well, there is this article by Peter-Paul Koch on a hack that allows
you to do custom file upload buttons. Maybe that'll give you what
you're looking for:

http://www.quirksmode.org/dom/inputfile.html

-David

Nov 25 '06 #7
David Golightly wrote:
Randy Webb wrote:
>><a
href="javascript:document.forms['upload'].elements['file_1'].click();">
>Because FF doesn't support the programmatic clicking of a file
input element.

This is true, but additionally, Firefox doesn't support the
click() method on any DOM object, at all.
<snip>

Firefox does support a - click - method on some elements. <IPUT
type="submit"elmenets spring to mind.

Richard.
Nov 26 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Tihon | last post: by
2 posts views Thread by matt | last post: by
7 posts views Thread by pbd22 | last post: by
Jacotheron
6 posts views Thread by Jacotheron | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.