Solved

Urgent: File Selector for image Uploading

Posted on 2006-06-30
7
242 Views
Last Modified: 2008-02-26
Hi i have an image with a javascript function for the onClick event

what i want to do is to open up a file selector when the image is clicked can anyone help with this please;
0
Comment
Question by:Robinsonx6
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 17017784
You could use an INPUT tag with style="display:non", and have your function change style to "display:inline".
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 17017797
<INPUT type=file ....

of course.
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 17017835
how do i fire the inputs click event, from within my javascript function so it works in all browsers please?

Kind Regards
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 17017957
You need a fileUploadControl which is basicaly an form input field of type=file and you need to hide it. Then you call the fileUploadControl click()  event on Image onclick event.
Like this:

<html>
<head>
<title>Zvonko &#42;</title>
</head>
<body>
<form name="myForm" enctype="multipart/form-data" method="post">
<input type="file" name="myFile" style="display:none;" onChange="document.getElementById('fName').innerHTML=this.value;this.form.Upload.style.display='';">
<span id="fName"></span>
<input type="submit" name="Upload" style="display:none;" value="Upload">
</form>
<img src="filesel.gif" onClick="document.forms[0].myFile.click()">
</body>
</html>


You see?

0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 17029903
hi Zvonko, thanks for this but it only works in ie not firefox any ideas on how to get it working in FF aswell please
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17029920
Sorry, it seams the FireFox is more restrictive with FileUpload features then IE.
A second observation that I had made with FileUpload is that as soon as you access by script any feature of the FileUpload object is the file not uploaded to server.
Sorry, but that all is security features of the browser.
I do not know how to upload a file by clicking on an image in FireFox.
By the way, calling click() of FileUploadControl does not throw an exception or error in FireFox. It simply does not do anything.
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 17029931
i hate coding for FF sometimes :-), thanks for your help
i will probably post this again
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tiny glitch in my main slider 3 39
innerHTML 7 35
Hide Table in merge 3 32
Explain this javascript function to me 2 29
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question