By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,944 Members | 1,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,944 IT Pros & Developers. It's quick & easy.

Designing file upload in FF

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a

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

P: n/a
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.