dynamically causing file browser to appear

W

walter-google

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
 
D

David Mark

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/window.showModalDialog
}

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

Thomas 'PointedEars' Lahn

David said:
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
 
W

walter-google

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
 
T

Thomas 'PointedEars' Lahn

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
 
D

David Mark

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.)
 
T

Thomas 'PointedEars' Lahn

David said:
Thomas said:
David said:
On Nov 1, 4:42 pm, (e-mail address removed) 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
 

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

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top