Designing file upload in FF

V

Victor

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
 
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
 
R

Randy Webb

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.
 
V

Victor

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 said:
Randy said:
<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
 
R

Richard Cornford

David said:
Randy said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top