Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js] radio i blokowanie input
max_mcee
post
Post #1





Grupa: Zarejestrowani
Postów: 156
Pomógł: 1
Dołączył: 25.09.2007

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


Jak wygląda kod, przykładowo w formularzu rejestracyjnym chcę, aby jeśli user zaznaczy firma to blokował się input PESEL, a przypadku osoba fizyczna odblokował się PESEL a zablokował REGON i NIP (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) Blokował w sensie nie można nic do tego wpisać.
Proszę o przykład i dziękuję (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował max_mcee 7.08.2008, 10:44:15
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
skowron-line
post
Post #2





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


  1. <input type="radio" name="firma" onclick="valid( '1' );">
  2. <input type="radio" name="fizyczna" onclick="valid( '2' );">


i js
  1. function valid( X ){
  2. document.getElementById( 'pesel' ).disabled = false;
  3. document.getElementById( 'regon' ).disabled = false;
  4. document.getElementById( 'nip' ).disabled = false;
  5. if( X == 1 ){
  6. document.getElementById( 'pesel' ).disabled = true;
  7. }else if( X == 2 ){
  8. document.getElementById( 'regon' ).disabled = true;
  9. document.getElementById( 'nip' ).disabled = true;
  10. }
  11. }
Go to the top of the page
+Quote Post
max_mcee
post
Post #3





Grupa: Zarejestrowani
Postów: 156
Pomógł: 1
Dołączył: 25.09.2007

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


  1. <?php
  2. <script language="javascript">
  3. function valid( X ){
  4. document.getElementById( 'pesel' ).disabled = false;
  5. document.getElementById( 'regon' ).disabled = false;
  6. document.getElementById( 'nip' ).disabled = false;
  7. if( X == 1 ){
  8. document.getElementById( 'pesel' ).disabled = true;
  9. }else if( X == 2 ){
  10. document.getElementById( 'regon' ).disabled = true;
  11. document.getElementById( 'nip' ).disabled = true;
  12. }
  13. }
  14. </script>
  15. <form action="" method="POST">
  16. firma <input type="radio" name="firma" onclick="valid( '1' );" /><br />
  17. osoba fizyczna <input type="radio" name="fizyczna" onclick="valid( '2' );" /><br />
  18. NIP: <input type="text" name="nip" /><br />
  19. REGON: <input type="text" name="regon" /><br />
  20. PESEL: <input type="text" name="pesel" /><br />
  21. </form>
  22. ?>

co robię źle bo to nie działa ?
Go to the top of the page
+Quote Post
skowron-line
post
Post #4





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


  1. <form action="" method="POST">
  2. firma <input type="radio" name="firma" onclick="valid( '1' );" /><br />
  3. osoba fizyczna <input type="radio" name="fizyczna" onclick="valid( '2' );" /><br />
  4. NIP: <input type="text" name="nip" id="nip" /><br />
  5. REGON: <input type="text" name="regon" id="regon" /><br />
  6. PESEL: <input type="text" name="pesel" id="pesel" /><br />
  7. </form>
Go to the top of the page
+Quote Post
max_mcee
post
Post #5





Grupa: Zarejestrowani
Postów: 156
Pomógł: 1
Dołączył: 25.09.2007

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


Jest jeszcze mały problem, a mianowicie podczas zaznaczania *firma bądź *osoba fizyczna, można zaznaczyć 2 radia...

(IMG:http://www.swiat-gsm.pl/dsads.jpg)
Go to the top of the page
+Quote Post
Shili
post
Post #6





Grupa: Zarejestrowani
Postów: 1 085
Pomógł: 231
Dołączył: 12.05.2008

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


Musisz dać im taki sam atrybut name, ale różne value.
Go to the top of the page
+Quote Post
sinke
post
Post #7





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 26.02.2011
Skąd: Bieruń

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


Witam,

przerobiłam skrypt, który podał powyżej skowron-line, ale niestety nie chce działać... (IMG:style_emoticons/default/sad.gif)
Moje przeróbki poniżej:
js:
  1. <script type="text/javascript">
  2. function valid( X ){
  3. document.getElementById( 'adresA3.1' ).disabled = false;
  4.  
  5. document.getElementById( 'adresA4.1' ).disabled = false;
  6. document.getElementById( 'adresA4.2' ).disabled = false;
  7.  
  8. document.getElementById( 'adresA5.1' ).disabled = false;
  9. document.getElementById( 'adresA5.2' ).disabled = false;
  10. document.getElementById( 'adresA5.3' ).disabled = false;
  11. document.getElementById( 'adresA5.4' ).disabled = false;
  12.  
  13. if( X == 1 )
  14. {
  15. document.getElementById( 'adresA3.1' ).disabled = true;
  16. }
  17. else if( X == 2 )
  18. {
  19. document.getElementById( 'adresA4.1' ).disabled = true;
  20. document.getElementById( 'adresA4.2' ).disabled = true;
  21.  
  22. }
  23. else if( X == 3 )
  24. {
  25. document.getElementById( 'adresA5.1' ).disabled = true;
  26. document.getElementById( 'adresA5.2' ).disabled = true;
  27. document.getElementById( 'adresA5.3' ).disabled = true;
  28. document.getElementById( 'adresA5.4' ).disabled = true;
  29. }
  30.  
  31. </script>


formularz html:
  1. <form action="" method="POST">
  2. <input type="radio" name="adres" onclick="valid( '1' );"> A3
  3. <select name="adresA3.1" id="adresA3.1" disabled="disabled">
  4. <option value="text" selected >text</option>
  5. <option value="text2" >text2</option>
  6. <option value="text3" >text3</option>
  7. <option value="text4" >text4</option>
  8. <option value="text5" >text5</option>
  9. </select>
  10. <br>
  11. <input type="radio" name="adres" onclick="valid( '2' );"> A4
  12. <select name="adresA4.1" id="adresA4.1" disabled="disabled">
  13. <option value="text" selected >text</option>
  14. <option value="text2" >text2</option>
  15. <option value="text3" >text3</option>
  16. <option value="text4" >text4</option>
  17. <option value="text5" >text5</option>
  18. </select>
  19. <select name="adresA4.2" id="adresA4.2" disabled="disabled">
  20. <option value="text" selected >text</option>
  21. <option value="text2" >text2</option>
  22. <option value="text3" >text3</option>
  23. <option value="text4" >text4</option>
  24. <option value="text5" >text5</option>
  25. </select>
  26. <br>
  27. <input type="radio" name="adres" onclick="valid( '3' );"> A5
  28. <select name="adresA5.1" id="adresA5.1" disabled="disabled">
  29. <option value="text" selected >text</option>
  30. <option value="text2" >text2</option>
  31. <option value="text3" >text3</option>
  32. <option value="text4" >text4</option>
  33. <option value="text5" >text5</option>
  34. </select>
  35. <select name="adresA5.2" id="adresA5.2" disabled="disabled">
  36. <option value="text" selected >text</option>
  37. <option value="text2" >text2</option>
  38. <option value="text3" >text3</option>
  39. <option value="text4" >text4</option>
  40. <option value="text5" >text5</option>
  41. </select>
  42. <select name="adresA5.3" id="adresA5.3" disabled="disabled">
  43. <option value="text" selected >text</option>
  44. <option value="text2" >text2</option>
  45. <option value="text3" >text3</option>
  46. <option value="text4" >text4</option>
  47. <option value="text5" >text5</option>
  48. </select>
  49. <select name="adresA5.4" id="adresA5.4" disabled="disabled">
  50. <option value="text" selected >text</option>
  51. <option value="text2" >text2</option>
  52. <option value="text3" >text3</option>
  53. <option value="text4" >text4</option>
  54. <option value="text5" >text5</option>
  55. </select>
  56. </form>


Nie działa to bo ma za dużo odwołań do selectów czy ja jednak coś źle przerobiłam??
Go to the top of the page
+Quote Post
kamil4u
post
Post #8





Grupa: Zarejestrowani
Postów: 2 350
Pomógł: 512
Dołączył: 4.01.2009
Skąd: Wrocław / Świdnica

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


Konsola błędów! Popatrz na liczbę nawisów.

PS. Nie czytałem tematu i nie wiem jak ma to działać (IMG:style_emoticons/default/smile.gif)
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: 25.12.2025 - 04:22