![]() |
![]() |
![]()
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"> |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 544 Pomógł: 5 Dołączył: 18.08.2009 Ostrzeżenie: (0%) ![]() ![]() |
Pomogło (prawie) wrzucenie check_upload(i) do funkcji EventListenera, ale nadal nie działa poprawnie. Konkretnie, przeglądarka pluje się że nie może odczytać VALUE z danego inputa. A to dlatego, że zmienna i wypluwa liczbę swoich iteracji a nie właściwą. Zawsze jest z tym problem w petli for...
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 14.10.2025 - 11:53 |