As of now my code looks like this:
$(document).ready(function (){
$("#p-image-1").on("change", function() {
var fileName = "";
fileName = $(this).val();
$("#file-image-1").html(fileName);
});
});
This will only display the name of the first image selected.
And this is my html.
<!---Upload 1----->
<label for="p-image-1" class="custom-file-upload"> Upload image </label>
<span id="file-image-1"></span>
<input type="file" id="p-image-1" class="product-file-upload" name="p-image-1" accept="image/jpeg">
<!---Upload 2----->
<label for="p-image-2" class="custom-file-upload"> Upload image </label>
<span id="file-image-2"></span>
<input type="file" id="p-image-2" class="product-file-upload" name="p-image-2" accept="image/jpeg">
<!---Upload 3----->
<label for="p-image-3" class="custom-file-upload"> Upload image </label>
<span id="file-image-3"></span>
<input type="file" id="p-image-3" class="product-file-upload" name="p-image-3" accept="image/jpeg">
Hiding all the input file in css.
.product-file-upload{
display:none;
}
Here is the live code. https://jsfiddle.net/xkevin/2qp98thx/
Questions:
What I would like to do is:
-In Jquery, What is the best/clean way to show the filename of the selected image?
In my mind it is like this:
$("#p-image-1").on("change", function() {
var fileName = "";
fileName = $(this).val();
$("#file-image-1").html(fileName);
});
$("#p-image-2").on("change", function() {
var fileName = "";
fileName = $(this).val();
$("#file-image-2").html(fileName);
});
so, just duplicating the code to other id of the file input.
or do it like this:
$("#p-image-1,#p-image-2,#p-image-3").on("change", function() {
but don't know what would be the next..
-Also how can I show the thumbnail of the image selected when the file name displays?
I have ten(10) input files here so it is a bit messy when I just duplicate the whole code of my existing jQuery code. Any help and guide is much appreciated! Thanks