input file question

F

Federico

Hello,

I can't find how to do this: I have an input of type=file and I want
that when the user clicks on it, javascript checks if some checkbox is
selected and if so, the file dialog is shown. If not, nothing is shown.

Any idea?
thanks in advance,
Federico
 
G

Grant Wagner

Federico said:
Hello,

I can't find how to do this: I have an input of type=file and I want
that when the user clicks on it, javascript checks if some checkbox is
selected and if so, the file dialog is shown. If not, nothing is shown.

Any idea?
thanks in advance,
Federico

Can't be done in a reliable, cross-browser, cross-platform way. You can't
make the file dialog open, on some operating systems, with some browsers,
there is no "file dialog". On other browsers and other platforms, there is
simply no way to achieve the desired affect.

<script type="text/javascript">
function testAndOpen(fi) {
var v;
if (fi &&
(v = fi.form) &&
(v = v.elements) &&
(v = v['autoOpen']) &&
v.checked &&
((v = typeof fi.click) == 'function' ||
(v == 'object' && v != null))) {

fi.click();
}
}
</script>
<form>
<input type="file" onfocus="testAndOpen(this, this.form);">
<input type="checkbox" name="autoOpen" checked="checked">
</form>

Works in: IE 6.0.2800 (on Windows XP)
Does not work in: Firefox 1.0PR, Netscape 4.78, Opera 6.05, Opera 7.54,
Mozilla 1.7.3 (on Windows XP)
 
L

Lee

Federico said:
Hello,

I can't find how to do this: I have an input of type=file and I want
that when the user clicks on it, javascript checks if some checkbox is
selected and if so, the file dialog is shown. If not, nothing is shown.

Instead, disable the file input unless the box is checked:

<form>
<input name="fileInput"
type="file"
disabled="true">
<br>
<input type="checkbox"
onclick="this.form.fileInput.disabled=!checked">
</form>
 
F

Federico

Lee said:
Federico said:



Instead, disable the file input unless the box is checked:

<form>
<input name="fileInput"
type="file"
disabled="true">
<br>
<input type="checkbox"
onclick="this.form.fileInput.disabled=!checked">
</form>

I already did so, but in Safari doesn't work. That's the reason I was
looking for what I asked.

Thanks to both of you. Finally, I leaved it as impossible and tried to
convince myself that it was not so important.
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top