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

dynamically causing file browser to appear

P: n/a
Hi,

I need to capture an event on a form file input button and present a
dialog before allowing the user to browse for a file. (A customer
needs this in a CMS that I'm customizing for them.) Capturing the
click is easy:
<form>
<input type="file" id="theButton" />
</form>

function theFunction() {
// do something
return false;
}

document.getElementById("theButton").onclick = theFunction;

The function presents a TOU in a div; when the user clicks "I Agree"
the browse dialog should appear. Everything works but forcing the
browse dialog to appear after accepting. I assumed something like

document.getElementById("theButton").onclick = theOriginalFunction;
document.getElementById("theButton").click();

would work, but no dice. focus() doesn't work, either.

Ideas? This needs to be cross-platform, but I'm developing on OS X w/
Firefox 3.

Thanks,

Walter
Nov 1 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Nov 1, 4:42*pm, walter-goo...@easypeas.net wrote:
Hi,

I need to capture an event on a form file input button and present a
dialog before allowing the user to browse for a file. *(A customer
needs this in a CMS that I'm customizing for them.) *Capturing the
click is easy:
What is this dialog supposed to do? Why do you feel you need to
present it just before the browser dialog?
<form>
* <input type="file" id="theButton" />
</form>
Actually, that is not a button.
>
function theFunction() {
* // do something
Showing a (non-standard) modal dialog is all you can do here. (FF3
and IE4+ are the only agents I know of that support this.)
* return false;
Return the appropriate value based on the result of the modal dialog.

https://developer.mozilla.org/en/DOM...howModalDialog
>
}

document.getElementById("theButton").onclick = theFunction;
The irritating thing about this is it breaks the accompanying
textbox. My host's "control panel" application does this, but then
they do a lot of stupid things.
Nov 1 '08 #2

P: n/a
David Mark wrote:
On Nov 1, 4:42 pm, walter-goo...@easypeas.net wrote:
>document.getElementById("theButton").onclick = theFunction;

The irritating thing about this is it breaks the accompanying
textbox. [...]
Looks like with Fx3/Win it has been broken already. I find it a rather
stupid default that a click on the accompanying textbox now works like a
click on the button; it makes the attempt at seeing what the full selected
filename is a PITA.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Nov 2 '08 #3

P: n/a
Thanks for your reply. At this point in development, I need to
justify changing our customer's wishes with a good reason. For this
reason, I'd like to know if it's possible to activate a file browse
input activity dynamically or not.

The customer is a national professional society, and requires that
people posting documents (done via the form I'm working on) agree to
their TOU. Their TOU statment is several paragraphs long; because of
this and aesthetic reasons, we decided to go against the modal dialog.

My research shows that overriding the browse button works in FF, IE
and Safari; these are the only browsers we test against or guarantee,
so if it doesn't work elsewhere, that's acceptable.

Probably a better way to do it would be to wait for the submit and
bring it there. A problem is that several documents can be attached
simultaneously (using the same input field), meaning a person may
browse for several documents and finally refuse the TOU, thus
potentially pissing them off.

Anyway, is the dynamic activation of a browse input possible? That's
what I really need to know now.

Thanks,

Walter

On Nov 1, 1:55*pm, David Mark <dmark.cins...@gmail.comwrote:
On Nov 1, 4:42*pm, walter-goo...@easypeas.net wrote:
Hi,
I need to capture an event on a form file input button and present a
dialog before allowing the user to browse for a file. *(A customer
needs this in a CMS that I'm customizing for them.) *Capturing the
click is easy:

What is this dialog supposed to do? *Why do you feel you need to
present it just before the browser dialog?
<form>
* <input type="file" id="theButton" />
</form>

Actually, that is not a button.
function theFunction() {
* // do something

Showing a (non-standard) modal dialog is all you can do here. *(FF3
and IE4+ are the only agents I know of that support this.)
* return false;

Return the appropriate value based on the result of the modal dialog.

https://developer.mozilla.org/en/DOM...howModalDialog
}
document.getElementById("theButton").onclick = theFunction;

The irritating thing about this is it breaks the accompanying
textbox. *My host's "control panel" application does this, but then
they do a lot of stupid things.
Nov 2 '08 #4

P: n/a
wa***********@easypeas.net wrote:
Thanks for your reply.
Which reply?
At this point in development, I need to justify changing our customer's
wishes with a good reason. For this reason, I'd like to know if it's
possible to activate a file browse input activity dynamically or not.
It's not. Satisfied?
The customer is a national professional society, [...]
Entirely irrelevant.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Nov 2 '08 #5

P: n/a
On Nov 2, 9:28*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
David Mark wrote:
On Nov 1, 4:42 pm, walter-goo...@easypeas.net wrote:
document.getElementById("theButton").onclick = theFunction;
The irritating thing about this is it breaks the accompanying
textbox. *[...]

Looks like with Fx3/Win it has been broken already. *I find it a rather
Really? As in, you can't select the text in the textbox at all?
Maybe it wasn't a bad script to blame after all (just a bad browser.)
Nov 3 '08 #6

P: n/a
David Mark wrote:
Thomas 'PointedEars' Lahn wrote:
>David Mark wrote:
>>On Nov 1, 4:42 pm, walter-goo...@easypeas.net wrote:
document.getElementById("theButton").onclick = theFunction;
The irritating thing about this is it breaks the accompanying
textbox. [...]
Looks like with Fx3/Win it has been broken already. I find it a rather

Really? As in, you can't select the text in the textbox at all?
You can select the text using a pointing device, but once you release the
button over the control you get the file select dialog like when you just
clicked anywhere within the control. In my "Mozilla/5.0 (Windows; U;
Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3" at least;
an extension might interfere, YMMV.
Maybe it wasn't a bad script to blame after all (just a bad browser.)
Maybe, although I would like to emphasize that this nasty little bug does
not make Firefox a bad browser :)
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Nov 3 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.