I am working on a site with bootstrap, where the input file does not show the selected file name. So I have a script that does the same.
But here it does not work with two inputs, so how to use the same with two inputs (two files upload).
Basically, I want to use the same script for two inputs. I hope you got what I want.
I don't know how to use IDs or other ways to make both inputs separate.
$(document).ready(function() {
$('input[type="file"]').change(function(e) {
var display = e.target.files[0].name;
$("h5").text(display + ' is the selected file.');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label for="profile_image" class="custom-file-label">Profile image</label>
<input files="true" class="custom-file-input" id="img1" name="profile_image" type="file">
<h5 style="color: rgb(4, 158, 4);"></h5>
<label for="profile_image" class="custom-file-label">Profile image</label>
<input files="true" class="custom-file-input" id="img1" name="profile_image" type="file">
<h5 style="color: rgb(4, 158, 4);"></h5>

e.target.nextSibling.innerTextinstead of$("h5")in the text assignment. By using the$("h5")selector, you've targeted ALLh5elements.