Forum Moderators: open

Message Too Old, No Replies

q: Can I change the button of the <input type="file"...> tag?

I wanna replace the standard button by a image

         

zipperX

11:33 am on Sep 27, 2001 (gmt 0)



Hi,

I use the <input type="file"...> tag in a html form but I would like to replace the button by a image.

Does anybody know how to do that?
Or do you know the rfc number?

hope for help,...
Stephan.

GWJ

11:47 am on Sep 27, 2001 (gmt 0)



This is what I am using...

<input border="0" src="images/whatever.gif" . I think there are different ways to call the image though so someone might offer another way.

Brian

zipperX

11:56 am on Sep 27, 2001 (gmt 0)



I checked this but it does'nt work :(

tedster

1:02 pm on Sep 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We were talking about this here a few month's ago but I couldn't locate the thread.

If I remember correctly, the consensus was that type="file" is a special case because it needs to interface with the user's OS to browse for the file. That's the reason that custom images don't work.

bcDarkAngel

10:40 am on Nov 1, 2001 (gmt 0)



hi.. im also trying to get this to work...

i read this on another forum

<div id="content1"
onmouseover="document.getElementById('fileName').value=
document.getElementById('buffer').value">
<h1 onclick="alert(document.getElementById('buffer').value)">Contact Page</h1>
<input id="buffer" style="display:none" type="file"
/>
<input type="text" size="30"
id="fileName" />
<input type="image" src="../img/warning.gif"
onclick="document.getElementById('buffer').click()" />

I've tried it, and variations of it... it does replace the "browse..." button with a custom button... and when you click on the button, it does open up the file selection menu... however, when i use this.. my upload code no longer works.. HELP!!!

donny

3:35 pm on Nov 13, 2001 (gmt 0)

10+ Year Member



If I understand correctly, the file selection is not being returned to the text box.
In your script:

<div id="content1"
onmouseover="document.getElementById('fileName').value= document.getElementById('buffer').value">,

the onmouseover wasn't working for me, so I got rid of this and put a onfocus event handler at the body level which is called on return from the choose file dialog box:
<BODY onfocus="document.getElementById('fileName').value= document.getElementById('buffer').value">
This worked for me, but remember that the event is called each and every time focus is returned to the page.

tedster

4:11 pm on Nov 13, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bcDarkAngel and donny,

Welcome to WebmasterWorld. Thanks to both of you for the excellent contributions.

donny, you said:
"...remember that the event is called each and every time focus is returned to the page.

What practical challenges do you see here? Is there a strong likelihood of an incorrect or useless file name being uploaded? Or is it more that the same file would be sent numerous times?

Also, I'm wondering why onMouseover wouldn't work. It's a simple thing and you may have accommodated it, but as posted here, the script doesn't close the <div> tag.

donny

4:34 pm on Nov 13, 2001 (gmt 0)

10+ Year Member



had a better look at this...

the onmouseover does work, but only when you move the mouse over the DIV (obviously!).
This means that the text box update doesn't happen automatically on return from the Choose File dialog, so it doesn't appear to work immediately.
I don't see a practical problem with the event being called repeatedly; it's just not as neat & tidy as I would like.

joshie76

9:59 am on Nov 14, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Corr! What a clever piece of script!

Had a look at it and the use of a mouseover event a is highly unreliable way of updating the text input. What if somebody was using the keyboard tab to move around the page. Instead you can abandon the div and move its event to the onChange event of the file input:


<input id="buffer" style="display:none" type="file" onchange="document.getElementById('fileName').value=document.getElementById('buffer').value" />
<input type="text" size="30" id="fileName" />
<input type="image" src="3T/images/disk.gif" onclick="document.getElementById('buffer').click()" />

This should be far more reliable. Needless to say that this script was only ever going to work with IE.