Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wartość input[type="file"] nie działa poprawnie?
deha21
post
Post #1





Grupa: Zarejestrowani
Postów: 544
Pomógł: 5
Dołączył: 18.08.2009

Ostrzeżenie: (0%)
-----


Mam problem ze zdarzeniem i odczytywaniem danych z input[type="file"]. Chcę zrobić tak że po wybraniu pliku, div .upload-button zmienia kolor. Mam taki kod:
Kod
var count = document.getElementsByClassName("upload").length;
var i=0;

for (i; i<count; i++) {
    document.getElementsByClassName("upload")[i].addEventListener("change", check_upload(i));
}

function check_upload(i) {
    if (document.getElementsByClassName("upload")[i].value!='') {
        document.getElementsByClassName("upload-button")[i].style.background="green";
        console.log("You have selected file to upload");
    } else {
        document.getElementsByClassName("upload-button")[i].style.background="red";
        console.log("No file choosen");
    }
}

Kod
<div class="upload-button"></div>
<input type="file" name="file" class="upload">
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 15:59