Solved

Urgent: File Selector for image Uploading

Posted on 2006-06-30
7
241 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now