0
Good evening guys I’m having a problem to call a class i want when the file button is with some file an icon appears (so to indicate that the button is not empty).
This function only works on the first button as I have another button to add more fields that calls this 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>
Thanks Marco was just what I wanted to do worked right
– Alex Peçanha