Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Dodanie i pokazanie obrazka po kliknięciu
BienuSS
post
Post #1





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 3.11.2017

Ostrzeżenie: (10%)
X----


Witam.
Mam na stronie 4 pola aby dodać obrazy, po dodaniu 1 wszystko sie ładnie zmienia i zapisuje. Jednak w pozostałych 3 juz nie działa. Jak dla mnie wina jest w zmiennej "file" jednak nie moge dojsc do rozwiązania problemuf
  1. function previewFile(q1) {
  2.  
  3. var preview = document.getElementById(q1);
  4. var file = document.querySelector('input[type=file]').files[0];
  5. var reader = new FileReader();
  6.  
  7. reader.addEventListener("load", function () {
  8. preview.src = reader.result;
  9. }, false);
  10.  
  11. if (file) {
  12. reader.readAsDataURL(file);
  13. }
  14. }
  15. </script>
  16.  
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
BienuSS
post
Post #2





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 3.11.2017

Ostrzeżenie: (10%)
X----


Przerobiłem w ten sposób obrazek wysyła ale nie pokazuje na żywo, plus jak zmieniam jeden obrazek to pozostałe sie kasują ...
  1. <input type="file" id="images-upload-input-1" accept=".png, .jpg, .jpeg" name="image_1" onchange="openFile('images-upload-input-1');" style='display: none;' />
  2.  
  3. FUNCTION openFile(q1) {
  4. var input = q1.target;
  5.  
  6. var reader = new FileReader();
  7. reader.onload = FUNCTION(){
  8. var dataURL = reader.result;
  9. var output = document.getElementById('img-new-1');
  10. output.src = dataURL;
  11. };
  12. reader.readAsDataURL(input.files[0]);
  13. input.readAsDataURL(output);
  14. };


jesli zmienie

  1.  
  2. <input type="file" id="images-upload-input-1" accept=".png, .jpg, .jpeg" name="image_1" onchange="openFile(event);" style='display: none;' />


to obrazek sie pokazuje ale nie wysyła.

Ten post edytował BienuSS 19.10.2020, 17:06:10
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: 14.10.2025 - 17:07