Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][PHP]Tablice z PHP do js
neo1986kk
post
Post #1





Grupa: Zarejestrowani
Postów: 561
Pomógł: 3
Dołączył: 2.02.2009

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


Witam chodzi o to że robie formularz i mam kilka pól checkbox.
Chciałbym aby walidacja js wskazywała na to że trzeba zaznaczyć przynajmniej 3.

  1. <input type="checkbox" name="nazwa[]">a</input>
  2. <input type="checkbox" name="nazwa[]">b</input>
  3. <input type="checkbox" name="nazwa[]">c</input>
  4. <input type="checkbox" name="nazwa[]">d</input>


  1. <script language="javascript">
  2. var ilosc// i tu nie wiem jak obliczyc ilosc elementów
  3. var tablica= new array()
  4. for (i=0; i<ilosc; i++)
  5. {
  6. tablica=nazwa[i];
  7. }
  8. if (i<3)
  9. {
  10. document.write('musisz zaznaczyc przynajmniej 3 pozycje');
  11. bledy=true;
  12. }
  13.  
  14.  
  15. </script>


no i oczywiście to nie dziala, pomożecie?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Wicepsik
post
Post #2





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

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


Kursu chyba nie czytałeś. Łap http://www.doman.art.pl/kursjs/kurs/formul...formularze.html
Go to the top of the page
+Quote Post
neo1986kk
post
Post #3





Grupa: Zarejestrowani
Postów: 561
Pomógł: 3
Dołączył: 2.02.2009

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


Dzięki, właśnie tego potrzebowałem, a jeszcze co do walidacji mam pytanie czy jak mam 10 różnych pól formularza typu text to musze dla każdego pisać osobny skrypt:
  1. function [b]spr[/b](nazwa,Div)
  2.  
  3. {
  4. var formularz = document.forms['wyslijf'];
  5. if(formularz.login.value == '')
  6. {
  7. document.getElementById(Div).style.background = ('red');
  8. document.getElementById(Div).innerHTML =
  9. nazwa;
  10. }
  11. else
  12. {
  13. document.getElementById(Div).style.background = ('lightblue');
  14. document.getElementById(Div).innerHTML =
  15. nazwa;
  16. }
  17. }
  18.  
  19. function [b]spr1[/b](nazwa,Div)
  20.  
  21. {
  22. var formularz = document.forms['wyslijf'];
  23. if(formularz.[b]imie[/b].value == '')
  24. {
  25. document.getElementById(Div).style.background = ('red');
  26. document.getElementById(Div).innerHTML =
  27. [b]imie[/b];
  28. }
  29. else
  30. {
  31. document.getElementById(Div).style.background = ('lightblue');
  32. document.getElementById(Div).innerHTML =
  33. [b]imie[/b];
  34. }
  35. }


Próbowałem takiego zapisu:
  1. function spr(nazwa,Div,[b]pole[/b])
  2.  
  3. {
  4. var formularz = document.forms['wyslijf'];
  5. if(formularz.[b]pole[/b].value == '')
  6. {
  7. document.getElementById(Div).style.background = ('red');
  8. document.getElementById(Div).innerHTML =
  9. [b]pole[/b];
  10. }
  11. else
  12. {
  13. document.getElementById(Div).style.background = ('lightblue');
  14. document.getElementById(Div).innerHTML =
  15. [b]pole[/b];
  16. }
  17. }



ale wyskoczył błąd...

Ten post edytował neo1986kk 8.03.2010, 21:56:30
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: 23.08.2025 - 03:06