I have two upload button (Upload Photo) & (Upload Signature). The issue is on same time only one button is uploading file second button is not uploading file, when I change the input ID on that time both buttons not working, I have placed both html code and script code and I want uploaded file name with path, Please fix the issue.
// This script is for photo upload button
const realFileBtn = document.getElementById("real-file-upload");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
realFileBtn.addEventListener("change", function() {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value.match(
/[\/\\]([\w\d\s\.\-\(\)]+)$/
)[1];
} else {
customTxt.innerHTML = "No file chosen, yet.";
}
});
// This script is for signature upload button
const realFileBtn = document.getElementById("real-file-upload");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
realFileBtn.addEventListener("change", function() {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value.match(
/[\/\\]([\w\d\s\.\-\(\)]+)$/
)[1];
} else {
customTxt.innerHTML = "No file chosen, yet.";
}
});
<div class="col-md-4">
<input type="file" id="real-file-upload" hidden="hidden" />
<button type="button" id="custom-button">Upload Photo</button>
<span id="custom-text">No file chosen, yet.</span>
</div>
<div class="col-md-4">
<input type="file" id="real-file-signature" hidden="hidden" />
<button type="button" id="custom-button">Upload Signature</button>
<span id="custom-text">No file chosen, yet.</span>
</div>