marcsimm marcsimm - 2 years ago 181
Javascript Question

Make button disabled if input type file is empty in bootstrap

I have form where the user can upload a file but I want the upload button to be disabled if the input type file does not contain a file how do I do that ?

<form action="/upload" method="post" enctype="multipart/form-data">
<div class="form-inline">
<div class="form-group">
<input type="file" name="fileUploaded">
<button type="submit" class="btn btn-sm btn-primary">Upload file</button>

Answer Source

you should add attribute disabled to the button

<button type="submit" class="btn btn-sm btn-primary" disabled>Upload file</button>

then we will watch changes with the code to enable the button when the input type file contain any file


Demo here :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download