473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

input file question

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
Jul 23 '05 #1
3 1330
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

Jul 23 '05 #2
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>

Jul 23 '05 #3
Lee wrote:
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>


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.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ron | last post by:
Hi, I'm still new at Python and have been away from programming for a number of years in general. I apologized in advance if this has been discussed extensively already. Is the input()...
2
by: Sonny | last post by:
Hi experts, I am writing a small code to read input from a file, for example my input file is: X Y Z 26.0 28.0 0.0 32.0 8.0 0.0 My code is:...
2
by: SophistiCat | last post by:
Hi, I am working on a computational program that has to read a number of parameters (~50) from an input file. The program contains a single class hierarchy with about a dozen member-classes or...
3
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
4
by: Petr Vileta | last post by:
Sorry if my question was be here earlier, I'm new here ;-) I have html form where is the tag <input id="x" type="file" name="upload"> and another fields. After submit script on server take some...
2
by: gonzo | last post by:
Say you have a .txt file with a random amount of numbers. Is there a way to initialize an array with that input file of numbers? After telling the program to open the input file, "inputFile," I...
12
by: Tarique | last post by:
I have tried to restrict the no. of columns in a line oriented user input.Can anyone please point out potential flaws in this method? btw.. 1.I have not used dynamic memory allocation because...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.