Manipulate text shown by input file multiple [closed]

1

Quick inquiry ...

I am working on a report form where images must be uploaded, for this purpose I have:

<input type="file" multiple>

My specific question is:

Can you manipulate in some way so that when you select a single file say 1 archivo (as you do when you select several) instead of showing the name of that single file?

    
asked by KuroNeko 04.04.2018 в 21:35
source

1 answer

2

It could be, but not directly in the input. But with javascript code, hiding the input and showing other elements instead.

For example:

function abrir(id) {
    var file = document.getElementById(id);
    file.dispatchEvent(new MouseEvent('click', {
        view: window,
        bubbles: true,
        cancelable: true
    }));
}
function contar(elem, idGlosa) {
    var glosa = document.getElementById(idGlosa);
    if(elem.files.length == 0) {
        glosa.innerText = "Ningun archivo seleccionado";
    } else {
        glosa.innerText = elem.files.length + " archivos";
    }
}
    <label for="archivo">Subir archivo</label>
    <button type="button"
            onclick="abrir('archivo')">Escoger archivos</button>
    <input type="file" multiple
           id="archivo" name="archivo"
           onchange="contar(this, 'glosaArchivos')" style="display: none">
    <span id="glosaArchivos">Ningun archivo seleccionado</span>

    
    
answered by 04.04.2018 / 23:01
source