I want to hide the file input "Choose file" button but I want to keep the filename. How can I do this?
<input
name="upload"
id="upload-input"
placeholder="Select a file"
ref="fileInput"
type="file"
required>
I want to hide the file input "Choose file" button but I want to keep the filename. How can I do this?
<input
name="upload"
id="upload-input"
placeholder="Select a file"
ref="fileInput"
type="file"
required>
You can save the file name to another html element and then hide the choose file input like this.
function getFileName()
{
var x = document.getElementById('upload-input')
x.style.visibility = 'collapse'
document.getElementById('fileName').innerHTML = x.value.split('\\').pop()
}
<input
name="upload"
id="upload-input"
placeholder="Select a file"
ref="fileInput"
type="file"
required
onchange="getFileName()"><span id="fileName"></span>
Add a new component at the place:
<span id='upload-file-name'></span>
With JavaScript, to get the file name first
var em = document.getElementById("upload-input");
var fname = em.name;
Hide the file upload input field
em.style.display = 'none';
Put the file name to this new component
document.getElementById("upload-file-name").innerHTML = fname;
you could use the color attribute in transparent in css to hide the letters of the filename but the button does not know
.inputfile{
opacity: 0;
}
<input
name="upload"
id="upload-input"
placeholder="Select a file"
ref="fileInput"
type="file"
class="inputfile"
required>
If you want to hide it you must put: display: none; But everything will be hidden without being able to use it. But if you want it to be invisible by regulating the opacity and adjusting the input it can work for you. But if you want to hide the button and the letters you can not put color: "any color"