Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] write
Wieczny
post
Post #1





Grupa: Zarejestrowani
Postów: 191
Pomógł: 1
Dołączył: 21.03.2007

Ostrzeżenie: (60%)
XXX--


Witam mam taki problem że gdy opuszczam input to powinno zmienić kolor obramowania a obok pojawić się napis błąd/ ok w zależności od tego czy dane są poprawne czy nie. Jednak nie działa mi to pierwsze tzn write gdy opuszczam input to następuje jak by przeładowanie pojawia się napis Błąd lecz już input nie bądź się pojawia lecz bardzo długo ładuje się strona tak jak by się zapętliło a to kod proszę (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
  1. document.write("Bląd").getElementById(id).style.borderColor='red';



edit Wszystko działa tylko gdy dodaje write to już nie ;]

Ten post edytował Wieczny 25.06.2008, 17:19:27
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
nevt
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


zrób tak:

Kod
getElementById(id).style.borderColor='red';
alert('Błąd!');
Go to the top of the page
+Quote Post
Wieczny
post
Post #3





Grupa: Zarejestrowani
Postów: 191
Pomógł: 1
Dołączył: 21.03.2007

Ostrzeżenie: (60%)
XXX--


ale nie chce okienka ... ;/
Go to the top of the page
+Quote Post
lilik
post
Post #4





Grupa: Zarejestrowani
Postów: 66
Pomógł: 5
Dołączył: 17.03.2005

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


moze sprobuj innerHTML
Go to the top of the page
+Quote Post
Wieczny
post
Post #5





Grupa: Zarejestrowani
Postów: 191
Pomógł: 1
Dołączył: 21.03.2007

Ostrzeżenie: (60%)
XXX--


tzn co to jest ? Nie zna nikt sposobu w Js ?
Go to the top of the page
+Quote Post
lilik
post
Post #6





Grupa: Zarejestrowani
Postów: 66
Pomógł: 5
Dołączył: 17.03.2005

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


  1. getElementById(id).style.borderColor='red';
  2. getElementById(id2).innerHTML='Błąd';


gdzie id2 to id diva w ktorym chcesz wyswietlic łańcuch 'Błąd'

a njaprosciej bys to na jQuery zrobil
Go to the top of the page
+Quote Post
nevt
post
Post #7





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


Cytat
tzn co to jest ? Nie zna nikt sposobu w Js ?

sposobu na co? na zmianę działania document.write() (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) tego po prostu nie robi się w ten sposób...
nie znasz składni JS, nie rozumiesz przykładów które dostajesz - o co i do kogo masz pretensje?
Go to the top of the page
+Quote Post
Wieczny
post
Post #8





Grupa: Zarejestrowani
Postów: 191
Pomógł: 1
Dołączył: 21.03.2007

Ostrzeżenie: (60%)
XXX--


  1. <?php
  2. <form action='index.php' method=post>
  3. <div id="2">test
  4. <input id="1" type="text" name="pole1" onchange="test(this.id, this.type, this.value)">
  5. </div>
  6. </form>
  7.  
  8. <script language='javascript'>
  9. function test(id, type, value)
  10. {
  11. if(document.getElementById(id).value=='xxx')
  12. {
  13.  
  14. document.getElementById(id).style.borderColor='red';
  15. document.getElementById(id2).innerHTML='Błąd';
  16. }
  17. else
  18. {
  19. document.getElementById(id).style.borderColor='green';
  20. }
  21. }
  22. </script>
  23. ?>


mam coś takiego i czegoś brakuje chyba muszę jeszcze do funkcji dopisać id z diva tylko zielonego pojęcia nie mam ;d
Go to the top of the page
+Quote Post
lilik
post
Post #9





Grupa: Zarejestrowani
Postów: 66
Pomógł: 5
Dołączył: 17.03.2005

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


a no brakuje kilku elemntow (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

  1. <form action='index.php' method=post>
  2. <div id="2">test
  3. <input id="pole1" type="text" name="pole1" onchange="test('pole1', 'info');"><span id="info"></span>
  4. </div>
  5. </form>
  6. <script language='javascript'>
  7. function test(id, id2)
  8. {
  9. if(document.getElementById(id).value=='xxx')
  10. {
  11.  
  12. document.getElementById(id).style.borderColor='red';
  13. document.getElementById(id2).innerHTML='Błąd';
  14. }
  15. else
  16. {
  17. document.getElementById(id).style.borderColor='green';
  18. }
  19. }

sprawdzalem dziala jak trzeba (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

dodalem dwa male ulepszenia i w ostatecznej dzialajacej formie masz

  1. <form action='index.php' method=post>
  2. <div id="2">test
  3. <input id="pole1" type="text" name="pole1" onkeyup="test('pole1', 'info');"><span id="info"></span>
  4. </div>
  5. </form>
  6. <script language='javascript'>
  7. function test(id, id2)
  8. {
  9. if(document.getElementById(id).value=='xxx')
  10. {
  11.  
  12. document.getElementById(id).style.borderColor='red';
  13. document.getElementById(id2).innerHTML='Błąd';
  14. }
  15. else
  16. {
  17. document.getElementById(id).style.borderColor='green';
  18. document.getElementById(id2).innerHTML=' ';
  19. }
  20. }


Ten post edytował lilik 25.06.2008, 20:29:34
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: 27.09.2025 - 19:46