Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Browse button in a form

160 views
Skip to first unread message

acey

unread,
Oct 22, 2001, 3:53:26 PM10/22/01
to
Hello,

I am a at a loss as to achieve this trick :

When u put in a form this :
<input type="file" name="file">
It gives u a field with a little grey button (awful isn't it :) )
Now, what I want to do is this :
u got an image in the webpage, when u click on it, it offers u the
same window as when u click on the button "file" browse : that is, the
image becomes the "browse button".

I thought of putting a href on my image which would call a function
which would emulate the onClick event on the button (which would be in
a hidden frame) but have not managed so far...

Any ideas please ?

Ranson

unread,
Oct 22, 2001, 5:28:34 PM10/22/01
to
I don't think there is any way to use an image here.

Ray

"acey" <kana...@yahoo.fr> wrote in message
news:976aea44.01102...@posting.google.com...

Greg

unread,
Oct 23, 2001, 12:55:25 AM10/23/01
to
Hey Ray, I am a total newbie and even I know the answer to this one ;)

acey

1. On your form, create a normal textfield and name it eg.
<input type="text" name="txtFileName">
this is to hold the name and path of the file

2. Next to your new text field, put the image you want. The image
should have the following onClick event
onClick="BrowseForFile()"

3. Add a HIDDEN Browse Field to your form eg.
<input type="file" name="BrowseDialog" style="display: none">

4. Add the following SCRIPT in the HEAD section of your page
(inbetween the <head> and </head> tags), like this

<head>
<script language="JavaScript">
function BrowseForFile() {
var browseObj = document.getElementById("BrowseDialog");
browseObj.click();
var txtLocation = document.getElementById("txtFileName");
txtLocation.value = browseObj.value;
}
</script>
</head>

5. Here is the completed page
<html>
<head>
<script language="JavaScript">
function BrowseForFile() {
var browseObj = document.getElementById("BrowseDialog");
browseObj.click();
var txtLocation = document.getElementById("txtFileName");
txtLocation.value = browseObj.value;
}
</script>
</head>
<body>
<form>
<input type="text" name="txtFileName">
<img src="Images/Button.png" onClick="BrowseForFile()">
<input type="file" name="BrowseDialog" style="display: none">
</form>
</body>
</html>

NOTE: I have tested this in IE 5.5 only. If you need it to run in
other browsers, I can't help you. As I said I am a total newbie.

Good luck

Greg


"Ranson" <ran...@rlaj.com> wrote in message news:<A70B7.3959$OB1.1...@eagle.america.net>...

acey

unread,
Oct 23, 2001, 3:58:27 PM10/23/01
to
Great !!

thnx a lot I did not know the event "BrowseForFile" : that solves it all

thank uvery much !


0 new messages