Basicly I want to hide the input file and use a button to choose a file in the form.
If I use <label for="input-file">Label</label>
when I click the label i get to choose a file, but I would like to be a button or at least to look like a button.
Here is a code sample in JSFiddle :
input[type=file] { display: none; }
<form>
<input type="file" id="input-file">
<label for="input-file">
<button>Button</button>
</label>
<input type="submit">
</form>
If I but a button in the label, it acts as a submit button, if I specify its type it does nothing on click.
Is there any way to have upload a file in the form using my button or a button looking control instead of using the input type="file"
?
It must be a HTML-CSS solution, no JS or any framework.
EDIT:
This CSS code appears to make the label
look like a standard button :
label {
appearance: button;
-moz-appearance: button;
-webkit-appearance: button;
text-align: center;
padding: 2px 6px 3px;
border: 2px outset buttonface;
font: 13.3333px Arial;
}
The only way to set the value of a file input is by the user to select a file. This is done for security reasons. Otherwise you would be able to create a JavaScript that automatically uploads a specific file from the client's computer.
call( inputs, function( input ) { var label = input. nextElementSibling, labelVal = label. innerHTML; input. addEventListener( 'change', function( e ) { var fileName = ''; if( this.
You can create a submit button by using the <input> element and setting the type attribute to 'submit'.
You'll achieve this with couple of lines of CSS. Fiddle
input[type="file"] {
display: none;
}
.custom-file-upload {
border: 1px solid #ccc;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
}
<label for="file-upload" class="custom-file-upload">
<i class="fa fa-cloud-upload"></i> Custom Upload
</label>
<input id="file-upload" type="file"/>
Your Html with simplte font awesome customization FIddle
.image-upload > input
{
display: none;
}
.attach-doc
{
cursor: pointer;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="image-upload">
<label for="file-input">
<i class="attach-doc fa fa-paperclip fa-2x" aria-hidden="true"></i>
</label>
<input id="file-input" type="file"/>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With