Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][JavaScript] Prosta vaildacja pola
o2w5n778
post
Post #1





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

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


Witam!
Dopiero co zaczynam moją przygodę z JavaScript. Chciałem napisać prostą funkcję która sprawdzała by mi czy podane pole nie jest puste, niestety coś skopałem i nie działa. Oto kod:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <title>Twoja opinia</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <link rel="stylesheet" href="style.css" />
  6. <script type="text/javascript">
  7. function isNotEmpty(pole){
  8. if(pole.value == ""){
  9. document.getElementById("i"+pole.id).innerHTML = "error";
  10. pole.ClassName = "blad";
  11. return false;
  12. } else {
  13. document.getElementById("i"+pole.id).innerHTML = "ok";
  14. pole.className = "ok";
  15. return true;
  16. }
  17. }
  18. isNotEmpty(pers);
  19. </script>
  20. </head>
  21. <div id="outer">
  22.  
  23. <form id="opinia" action="#" method="get">
  24. <div class="row">
  25. <div class="lr">Imię i nazwisko:</div>
  26. <div class="rr"><input type="text" id="pers" name="pers" /></div>
  27. <div id="ipers" class="info"></div>
  28. </div>
  29. <div>
  30. <div class="submit"><input type="submit" value="Prześlij" /></div>
  31. </div>
  32. </form>
  33.  
  34. </div>
  35. </body>
  36. </html>
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: 19.09.2025 - 19:30