Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript][PHP]Identyfikacja diva (który znajduje sie w pętli foreach) w JS
BienuSS
post 28.11.2017, 21:05:10
Post #1





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

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


Witam.
Potrzebuje funkcji która w JS zastąpi mi getElement by ID, ponieważ nie działa mi ta funkcja gdy jest w kodzie pętli foreach

Kod
<input onkeyup='document.getElementById('win".$i."').innerHTML = this.value;' /><br/><br/>

<div id='win".$i."'>Potential win:</div></br>
Go to the top of the page
+Quote Post
trueblue
post 28.11.2017, 21:09:57
Post #2





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

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


Jeżeli element ma nadane poprawne id i dla funkcji getElementById również przekazujesz poprawne (to samo) id, to nie ma problemów.

Pokaż przykład tego foreach.

P.S. Zainteresuj się obsługą zdarzeń poprzez dołączanie listenerów do elementów: https://developer.mozilla.org/pl/docs/Web/A...ddEventListener


--------------------
Go to the top of the page
+Quote Post
BienuSS
post 28.11.2017, 21:25:13
Post #3





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

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


Tylko że w źródle strony na serwerze już.
Kod
.innerHTML
bierze jeszcze jako tekst w "" bo wyświetla sie na brązowo, chociaż wcześniej wszystko poprawnie zamknąłem

Ten post edytował BienuSS 28.11.2017, 21:58:03
Go to the top of the page
+Quote Post
trueblue
post 28.11.2017, 21:37:40
Post #4





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

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


Pokaż fragment źródło, razem z tym "bronzowym".


--------------------
Go to the top of the page
+Quote Post
BienuSS
post 28.11.2017, 22:01:26
Post #5





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

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


Polska trudny język biggrin.gif na szybko pisałem ale i tak wstyd sad.gif
Źródło
Go to the top of the page
+Quote Post
trueblue
post 28.11.2017, 22:04:05
Post #6





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

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


Jako argument dla funkcji getElementById przekazujemy id elementu (nie selektor #id).


--------------------
Go to the top of the page
+Quote Post
BienuSS
post 28.11.2017, 22:07:42
Post #7





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

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


Poprawione i tak dalej nie działa sad.gif
Go to the top of the page
+Quote Post
trueblue
post 28.11.2017, 22:13:10
Post #8





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

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


Wklej tu źródło tego input + div, ale nie jako obrazek.


--------------------
Go to the top of the page
+Quote Post
BienuSS
post 28.11.2017, 22:20:47
Post #9





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

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


  1. <div id='1".$i['id_match']."' class='betwindow'>
  2.  
  3. <p><b>Your bet: </b></p>
  4.  
  5. <form action='place_bet.php' method='post' class='betBox'>
  6.  
  7. <center><input type='text' id='value_coins' name='value_coins' autocomplete='off'
  8.  
  9.  
  10.  
  11. onkeydown='return ( event.ctrlKey || event.altKey
  12. || (47<event.keyCode && event.keyCode<58 && event.shiftKey==false)
  13. || (95<event.keyCode && event.keyCode<106)
  14. || (event.keyCode==8) || (event.keyCode==9)
  15. || (event.keyCode>34 && event.keyCode<40)
  16. || (event.keyCode==46) )'
  17.  
  18. onkeyup='document.getElementById('win".$i['id_match']."').innerHTML = this.value;' /><br/><br/>
  19.  
  20. <div id='win".$game['id_match']."'>Potential win:</div></br>
  21. <input type='submit' name='submit' id='Submit'></center>
  22.  
  23.  
  24. </form>
  25.  
  26.  
  27.  
  28.  
  29. </div>
  30.  


Ten post edytował BienuSS 28.11.2017, 22:21:55
Go to the top of the page
+Quote Post
trueblue
post 28.11.2017, 22:29:13
Post #10





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

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


Kod
onkeyup='document.getElementById('win2').innerHTML = this.value;'

Nie widzisz tu nic dziwnego?


--------------------
Go to the top of the page
+Quote Post
BienuSS
post 28.11.2017, 22:36:09
Post #11





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

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


No właśnie nie......
Go to the top of the page
+Quote Post
Pyton_000
post 28.11.2017, 23:17:27
Post #12





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Podpowiem: '
Go to the top of the page
+Quote Post
BienuSS
post 29.11.2017, 19:24:02
Post #13





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

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


Powtarzam że to jest kod w foreach'u czyli ' bierze jako "

To ma ktoś jeszcze jakiś pomysł questionmark.gif

Ten post edytował BienuSS 29.11.2017, 23:26:52
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 16.06.2025 - 19:26