Federico wrote:
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)
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq