Reputation: 1558
I have a html input type file control. When I select a file with very big name, it shows complete filename in firefox which causes bad UI. Is there any solution for this problem like changing name etc?
Upvotes: 3
Views: 5072
Reputation: 1510
There is three possible answers I know:
Upvotes: 1
Reputation: 3956
You can handle it this way:
input file
control hidden and add onchange
event handler to change selected file nametextbox
control for showing changed file namebutton
control with onclick
event handler to trigger file control's click eventHTML:
<input type="text" id="txtFile" readonly="true" />
<input type="button" id="btn" value="Browse..." onclick="browseFile();" />
<input type="file" id="file1" name="file1" onchange="setFileName(this.value);" />
CSS:
#file1 {
display: none;
}
JS:
function browseFile() {
document.getElementById('file1').click();
}
function setFileName(fileName) {
/* Manipulate file name here */
fileName = fileName.substr(0, fileName.lastIndexOf('.'));
document.getElementById('txtFile').value = fileName;
}
Upvotes: 3