Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Input radio JS
neo1986kk
post
Post #1





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

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


Witam, chcialbym zrobić coś takiego że mam 2 tabele:

|uzyj tabeli a i tu <input type radio>|uzyj tabeli b i tu <inpu type radio>
| tu jest tr id=tab1 | tu jest tr id =tab2
i tak w dół
i teraz chce uzyskac coś takiego że jak kliknę "uzyj tabeli a" to zniknie mi tr id=tab2

zrobiłem coś takiego:
  1. function wydajp()
  2.  
  3. {
  4. var formularz = document.forms['tabele'];
  5. if(formularz.tabela.value == 'on')
  6. {
  7. document.getElementById('tab1').style.display = 'none';
  8. document.getElementById('tab2').style.display = 'block';
  9.  
  10. }
  11.  


no i dziala, ale jak klikne uzyj tabeli b to sie dzieje to samo bo <input radio ma tą samą nazwę = tabela, a przecież nie moge zmienić nazwy.

teraz tak: dlaczego value jest on?? skoro ja wpisałem <input type radio value="1"> wtedy by bylo prosciej bo na drugi bym ustawił value 2 i po wszystkim, radio przybiera value on/off?

A może radio nie jest tu dobrym rozwiązaniem?
Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
mortus
post
Post #2





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Radio wydaję się być dobrym rozwiązaniem, a dzieje się to samo, ponieważ to się ma dziać:
Cytat(neo1986kk @ 2.03.2010, 13:19:36 ) *
  1. document.getElementById('tab1').style.display = 'none';
  2. document.getElementById('tab2').style.display = 'block';
Wydaje mi się natomiast, że algorytm powinien być nieco inny. W pierwszym kroku ukrywamy wszystkie tabele, a w drugim pokazujemy tą, do której odnosił się przycisk radio. Sam sprawdź:
  1. <head>
  2. <script type="text/javascript">
  3. function showOnlyThisTable(emt) {
  4. tabele = document.getElementsByTagName('table');
  5. for (var i = tabele.length - 1; i >= 0; i--){
  6. tabele[i].style.visibility = 'hidden';
  7. };
  8. document.getElementById('tab' + emt.value).style.visibility = 'visible';
  9. }
  10. </script>
  11. </head>
  12. <body>
  13. <form action="index.php" method="post">
  14. <input type="radio" name="tabela" value="a" onclick="showOnlyThisTable(this);"/>Wybierz tabelę A<br/>
  15. <input type="radio" name="tabela" value="b" onclick="showOnlyThisTable(this);"/>Wybierz tabelę B<br/>
  16. </form>
  17. <table id="taba">
  18. <tr><td>taba</td></tr>
  19. </table>
  20. <table id="tabb">
  21. <tr><td>tabb</td></tr>
  22. </table>
  23. </body>
  24. </html>
Radio zwraca swoją własną wartość ustawioną poprzez value!
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%)
-----


  1. <li class="li1"> <[url="http://december.com/html/4/element/script.html"]script[/url] type="text/javascript"><li class="li2"> function showOnlyThisTable(emt) {<li class="li1"> tabele = document.getElementsByTagName('table');<li class="li2"> for (var i = tabele.length - 1; i >= 0; i--){<li class="li1"> tabele[i].style.visibility = 'hidden';<li class="li2"> };<li class="li1"> document.getElementById('tab' + emt.value).style.visibility = 'visible';<li class="li2"> }<li class="li1"> </[url="http://december.com/html/4/element/script.html"]script[/url]>

tego nie miałem nie miałem pętli tylko poprostu chciałem działać na value
zaraz zobacze co z tego bedzie.
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: 24.08.2025 - 09:12