Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z innerHTML
diamondking
post
Post #1





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Cześć.
Mam dwa osobne ale identyczne formularze, w każdym jest pole file z innym id.

W JS mam skrypt by podczas zmiany tego pola usuwało zawartość z diva.

  1. $('#avatarimg').on('change', function() {
  2. document.getElementsByClassName('noti')[0].innerHTML = '';
  3. });


tak samo w drugim

  1. $('#bgimg').on('change', function() {
  2. document.getElementsByClassName('noti')[0].innerHTML = '';
  3. });


W pierwszym formularza działa poprawnie, w drugim już nie. Pomożecie?
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




NO skoro zawsze pobierasz pierwszy element o klasie noti no to sie nie dziw ze zawsze ci zmienia tylko w pierwszym (IMG:style_emoticons/default/wink.gif)

ps: przenosze

Swoja droga skoro uzywasz jquery to moglbys to robic konsekwentnie a nie raz jquery a raz lecisz w vanila js
Go to the top of the page
+Quote Post
diamondking
post
Post #3





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Ty jak zawsze pomocy (IMG:style_emoticons/default/facepalmxd.gif)

jak zmieniłem na
  1. document.getElementsByClassName('noti').innerHTML = '';


to nie działa w ogóle (IMG:style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Ale jakbys zamienil na
document.getElementsByClassName('noti')[1].innerHTML = '';

to moze byc jednak zadzialalo (IMG:style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post
diamondking
post
Post #5





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Niestety nie działa, widocznie gdzie indziej w kodzie mam jakiś błąd (IMG:style_emoticons/default/smile.gif)
Tworzę to na przykładach z sieci bo nie znam się na JS ;/

  1. $('#avatarimg').on('change', function() {
  2. var buttonblock = document.getElementById("avatarsend");
  3. if(this.files[0].size > 2097152){
  4. buttonblock.classList.add("disabled");
  5. document.getElementsByClassName('txtavatar')[0].innerHTML = '<span class="error">Maksymalny rozmiar pliku 2Mb</span>';
  6. }else{
  7. buttonblock.classList.remove("disabled");
  8. document.getElementsByClassName('txtavatar')[0].innerHTML = '';
  9. }
  10. document.getElementsByClassName('noti')[1].innerHTML = '';
  11. });


pod spodem mam taki kod do drugiego pola

  1. $('#bgimg').on('change', function() {
  2. var buttonblock = document.getElementById("bgsend");
  3. if(this.files[0].size > 2097152){
  4. buttonblock.classList.add("disabled");
  5. document.getElementsByClassName('txtbg')[0].innerHTML = '<span class="error">Maksymalny rozmiar pliku 2Mb</span>';
  6. }else{
  7. buttonblock.classList.remove("disabled");
  8. document.getElementsByClassName('txtbg')[0].innerHTML = '';
  9. }
  10. document.getElementsByClassName('noti')[1].innerHTML = '';
  11. });
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




(IMG:style_emoticons/default/facepalmxd.gif)
Nie musisz sie znac, ale myslec to bys mogl... Przeczytaj dokladnie co ja pisalem w postach i przetraw to na spokojnie patrzac na to co ty zastosowales
Go to the top of the page
+Quote Post
diamondking
post
Post #7





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Daruje sobie to (IMG:style_emoticons/default/biggrin.gif) Nie ogarniam. Google też nie pomaga chyba, że będziesz tak miły i podrzucisz jakiś link (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




console.log(document.getElementsByClassName('noti'));
co zwraca?
Go to the top of the page
+Quote Post
diamondking
post
Post #9





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 7.02.2014

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


Nie wiem co się stało ale zaczęło działać (IMG:style_emoticons/default/nerdsmiley.png)
Go to the top of the page
+Quote Post

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: 26.08.2025 - 03:50