Good evening guys I'm having a problem calling a class I want that when the file button is with some file an icon will appear (only to indicate that the button is not empty).
This function only works on the first button, because I have another button to add more fields that calls that file button again.
<html>
<body onload="myFunction()">
<input type="file" id="myFile" multiple size="50" onchange="myFunction()">
<p id="demo"></p>
<br>
<br><button onclick="myFunction2()"> mais campos </button>
<script>
function myFunction(){
var x = document.getElementById("myFile");
var txt = "<img src='ok.png'>"
if ('files' in x) {
if (x.files.length == 0) {
txt = "Selecione um arquivo.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += "<br><strong>" + (i+1) + ". file</strong><br>";
var file = x.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
}
}
}
document.getElementById("demo").innerHTML = txt;
}
function myFunction2() {
var x = document.createElement("INPUT");
x.setAttribute("type", "file");
document.body.appendChild(x);
}
</script>
</body>
</html>