Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] Sprawdzanie input radio z różnymi nazwami i nieznaną ilością input radio
harbii
post
Post #1





Grupa: Zarejestrowani
Postów: 311
Pomógł: 1
Dołączył: 27.05.2006

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


Kolejny problem z formularzem.

  1. var xxx = -1;
  2. var stan = document.getElementById('formularz').stan
  3.  
  4. for (x=0; x<stan.length; x++) {
  5. if (stan[x].checked) {
  6. xxx = x;
  7. break;
  8. }
  9. }
  10. if (xxx == -1) {
  11. alert('Nie zaznaczyles żadnego pola!');
  12. }


Powyższy skrypt sprawdza input radio z name=stan

A jak sprawdzić nieznaną ilość radio'nów, które tworz się same w sposób:
stan1
stan2
stan3
stan4 itd ?



Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
8_pasarzer_NOSTR...
post
Post #2





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 5.11.2009

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


Witam

Podłącze się pod wątek.

Mam formularz, który sprawdza wszystkie radio w formularzu. A ja chce tylko wybrane.

  1. function checkRadio() {
  2. var inputs = document.getElementById('fo2').getElementsByTagName('input');
  3.  
  4. var noneChecked = true;
  5. for(var i = 0; i < inputs.length; i++) {
  6. if(inputs[i].type != 'radio') continue;
  7. if(inputs[i].checked) {
  8. noneChecked = false;
  9. break;
  10. }
  11. }
  12. if(noneChecked) {alert('Nie zaznaczono żadnego radio!');}
  13. return false;
  14. }


  1. <form method="post" id="fo2" onsubmit="return checkRadio();">
  2. $ile=count($id);
  3. for($x=0;x<=$ile;$x++)
  4. {<input type="radio" name="r1" value="0"/> aaa}
  5. <br />
  6. <input type="radio" name="r2" value="0"/> Opcja 1
  7. <input type="radio" name="r2" value="0"/> Opcja 2
  8. <input type="radio" name="r2" value="0"/> Opcja 3
  9. <input type="submit" value="Wyślij"/>


Chce żeby skrypt sprawdzał tylko pole name=r1. Bo tylko to jest wymagane, r2 może być puste.
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: 15.10.2025 - 15:06