Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Sprawdzanie formularza rozbijanie na funkcje
imosek8
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 26.08.2013

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


Witam! Tworze formularz, sprawdzam go juz przed wyslaniem formularza, aby dynamicznie pokazywalo co jest zle wpisane.
mam cos takiego:
to jest w inpucie:
  1. <input type="text" name="login" placeholder="Login" class="forlog2" id="login" onclick="checking('login','3','10')" onkeyup="checking('login','3','10')">


a funkcja wygląda tak:

  1. function checking(id,min,max)
  2. {
  3. var x = document.getElementById(id);
  4. var length = parseInt(x.value.length);
  5. if(x.value ==''){
  6. x.removeError();
  7. x.createTitleError('To pole musi być wypełnione.');
  8. return false;
  9. }
  10. if(length <min)
  11. {
  12. x.removeError();
  13. x.createTitleError('Minimalna długość pola to '+min+' znaki.');
  14. return false;
  15. }
  16. if(length >max)
  17. {
  18. x.removeError();
  19. if(max>=5){
  20. x.createTitleError('Maksymalna długość pola to '+max+' znaków.');}
  21. if(max>=5){
  22. x.createTitleError('Maksymalna długość pola to '+max+' znaki.');}
  23. return false;
  24. }
  25. else{
  26. x.removeError();
  27. return true;
  28. }
  29. }


no i mi to ladnie dziala....

ale jak juz rozbijam to na mniejsze funkcje to nie dziala to wyglada tak:

input zostaje ten sam, a funkcje:

  1. function checkIsEmpty(id){
  2. var x = document.getElementById(id);
  3. if(x.value ==''){
  4. x.removeError();
  5. x.createTitleError('To pole musi być wypełnione.');
  6. return false;
  7. }
  8.  
  9. function checking(id,min,max)
  10. {
  11. var x = document.getElementById(id);
  12. var length = parseInt(x.value.length);
  13. checkIsEmpty(id);
  14. if(length <min)
  15. {
  16. x.removeError();
  17. x.createTitleError('Minimalna długość pola to '+min+' znaki.');
  18. return false;
  19. }
  20. if(length >max)
  21. {
  22. x.removeError();
  23. if(max>=5){
  24. x.createTitleError('Maksymalna długość pola to '+max+' znaków.');}
  25. if(max>=5){
  26. x.createTitleError('Maksymalna długość pola to '+max+' znaki.');}
  27. return false;
  28. }
  29. else{
  30. x.removeError();
  31. return true;
  32. }
  33. }
  34. }

to juz mi nie dziala... co powinienem zrobic aby działało?
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: 6.10.2025 - 17:36