2

I need to change the "Browse" button text according to the locale in a JSP. (Ex. Russian , Portuguese) for a Spring based project.

Following is the current implementation for the browse button

<td><input type="file" id="file" name="fileName"/></td>

enter image description here

As I know we can't change the text for input type file. It's the default behavior for a browse button int he browser.

I tried the following solution

<input type="button" id="button" value="Browse"/>
<input type="file" id="fileName"  style="opacity:0; position:relative; left:-40px;"  onchange="javascript: document.getElementById ('fileName').value = this.value"/>

enter image description here

But above one is giving security issue in the browser.


In https://stackoverflow.com/ it's having the ideal solution for this (change text for the browse button using input type file):

enter image description here

<input type="file" name="filename" id="filename-input" value="browse" size="18" style="float: right; width: 250px;">

Can anyone help me to resolve this problem or the way to implement above solution( https://stackoverflow.com/ file upload).

Community
  • 1
  • 1
Chamith Malinda
  • 4,399
  • 5
  • 24
  • 28
  • what kind of security issue it gives? – Jaiwo99 Jul 24 '14 at 07:54
  • Possible duplicate of [How to change the button text of ?](https://stackoverflow.com/questions/1944267/how-to-change-the-button-text-of-input-type-file) – Bae Aug 04 '17 at 00:03

2 Answers2

0

You might be looking for this answer to a similar question.

It suggests using Bootstrap File-system css styling.

Community
  • 1
  • 1
Prakash K
  • 11,669
  • 6
  • 51
  • 109
0

suggest you to do it this way to keep it simple:

<input type="file" style="display:none"/>
<button id="browse">whatever</button>

$('#browse').click(function(){
    $('input[type="file"]').trigger('click');
});
Jaiwo99
  • 9,687
  • 3
  • 36
  • 53