tags:

views:

265

answers:

3
<input type="file" value="Browse" name="avatar" id="id_avatar" />

I tried to modify the value, but it's not working. How to customize the button text?

+9  A: 

The "upload file..." text is pre-defined by the browser and can't be changed. The only way to get around this is to use a Flash- or Java-based upload component like swfupload.

Pekka
Can you prove it that it can't be changed?
@OP It should be possible to find in the XHTML docs.
jensgram
Or by browsing the browsers' source codes, at least for the Open Source ones.
Pekka
Hey, where did the other answer go? It was much more elaborate.
Pekka
I removed it because I thought I misunderstood the question. I'll add it back so you can look at it again.
Asaph
Ah, I hadn't realized the discrepancy between label and value. Thanks for adding it back.
Pekka
@Pekka: Ok, I'm removing it again. It' a good answer but to a different question.
Asaph
@Asaph D: I am also interested in your answer! Do you have some kind of reference? E.g. to another question on Stack Overflow or some web page.
Peter Mortensen
This could by the answer (to another question, something like "Why is the content of value, 'VALUE="C:\someFile.txt"' for an input field of type file, 'TYPE="FILE"', ignored by the browser?"): http://stackoverflow.com/questions/1342039
Peter Mortensen
@Peter Mortensen: Ok, I'll undelete my answer.
Asaph
+1  A: 

EDIT: I see now by the comments that you are asking about the button text, and not the file path. My bad. I'll leave my original answer below in case someone else who stumbles upon this question interprets it the way I originally did.

2nd EDIT: I had deleted this answer because I decided that I misunderstood the question and my answer was not relevant. However, comments in another answer indicated that people still wanted to see this answer so I'm undeleting it.

MY ORIGINAL ANSWER (I thought the OP was asking about the path, not the button text):

This is not a supported feature for security reasons. The Opera web browser used to support this but it was removed. Think about what would be possible if this were supported; You could make a page with a file upload input, pre-populate it with a path to some sensitive file and then auto-submit the form using javascript triggered by the onload event. This would happen too fast for the user to do anything about it.

Asaph
A: 

You can change it with a good shot of CSS/JS. This is discussed here and there fairly a lot. The one at quirksmode.org is a good article.

BalusC