Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Ukrywanie i ujawnianie inputów
adeq_PL
post
Post #1





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 25.01.2006
Skąd: Oświęcim

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


Witam.

Mam nastepujacy problem. Napisalem formularz, ktorego zrodlo znajduje sie ponizej i chcialbym do niego dorobic nastepujacy skrypt.

Chcialbym zeby po zaznaczeniu checkboxa pojawialy sie 4 pozostale imputy, ktore sa typu text, natomiast po jego odznaczeniu chcialbym zeby sie ukrywaly.

A oto i kod:

  1. <?php
  2.  
  3. $tablica = array ("Pn.-Pt.", "Poniedziałek", "Wtorek", "&para;roda", "Czwatrek", "Pi&plusmn;tek", "Sobota", "Niedziela");
  4.  
  5. echo "<table width=350 cellpadding='1' cellspacing='0'>";
  6.  
  7. for($ile=0;$ile<=7;$ile++){
  8.  
  9.  echo "<tr><td align='left'>";
  10.  
  11.  echo "<input type='checkbox' name='dni[]' value=$tablica[$ile]>
  12.  <font class=edytuj>$tablica[$ile]</font>
  13.  </td><td>
  14.  
  15. <font class=edytuj> od: </font>
  16. <input type='text' size='1' name='godzod[$ile]' maxlength='2'> 
  17. <font class=edytuj> : </font>
  18. <input type='text' size='1' name='minod[$ile]' maxlength='2'>
  19. <font class=edytuj> do: </font>
  20. <input type='text' size='1' name='godzdo[$ile]' maxlength='2'>
  21. <font class=edytuj> : </font>
  22. <input type='text' size='1' name='mindo[$ile]' maxlength='2'>";
  23.  
  24. echo "</td></tr>";
  25. }
  26. echo "</table>";
  27.  
  28. ?>


Mam nadzieje ze jest to mozliwe do realizacji. Dzieki za kazda pomoc (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




http://forum.php.pl/index.php?showtopic=27030&hl=
Go to the top of the page
+Quote Post
adeq_PL
post
Post #3





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 25.01.2006
Skąd: Oświęcim

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


Dzieki, ale przegladalem tego posta i probowalem nawet go zastosowac w moim skrypcie oto co sie mi udalo stworzyc, choc i tak to nie dziala.....


Kod
<script language='JavaScript'>

function show()
{
obj=document.getElementById('id[$ile]');
obj.style.display='';
obj=document.getElementById('id[$ile]');
obj.style.display='';
obj=document.getElementById('id[$ile]');
obj.style.display='';
obj=document.getElementById('id[$ile]');
obj.style.display='';
}

</script>


  1. <?php
  2. $tablica = array ("Pn.-Pt.", "Poniedziałek", "Wtorek", "&para;roda", "Czwatrek", "Pi&plusmn;tek", "Sobota", "Niedziela");
  3.  
  4.  echo "<table width=350 cellpadding='1' cellspacing='0'>";
  5.  
  6. for($ile=0;$ile<=7;$ile++){
  7.  
  8.  echo "<tr><td align='left'>";
  9. echo "<input type='checkbox' onchange='show()' name='dni[]' value=$tablica[$ile]>
  10.  <font class=edytuj>$tablica[$ile]</font>
  11.  </td><td>
  12.  
  13. <font class=edytuj> od: </font>
  14. <input type='text' id='id[$ile]' size='1' name='godzod[$ile]' style='display:none' maxlength='2'> 
  15. <font class=edytuj> : </font>
  16. <input type='text' id='id[$ile]' size='1' name='minod[$ile]' style='display:none' maxlength='2'>
  17. <font class=edytuj> do: </font>
  18. <input type='text' id='id[$ile]' size='1' name='godzdo[$ile]' style='display:none' maxlength='2'>
  19. <font class=edytuj> : </font>
  20. <input type='text' size='1' id='id[$ile]' name='mindo[$ile]' style='display:none' maxlength='2'>";
  21.  
  22. echo "</td></tr>";
  23.  
  24.  }
  25.  
  26.  
  27. echo "</table>"; 
  28.  
  29. ?>


Js staram sie dopiero poznac, dlatego prosze o propozycje jak ty zmodyfikowalbys moj kod do tego skryptu?
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




ten kod js co pokazales, to ty generujesz przez php? Bo uzywasz w nim zmiennych php
Go to the top of the page
+Quote Post
adeq_PL
post
Post #5





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 25.01.2006
Skąd: Oświęcim

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


Tak wlasciwie to ja to zle tu napisalem, poniewaz ten skrypt JS mam zawarty w petli for w echo"";

Nie wiem pewno tak nie moze byc a jest to jedynie wytwor metody prob i bledow jaka zastosowalem... (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Bylbym baaardzo wdzieczny gdybys mi powiedzial jak ty to widzisz i naprowadzil mnie na dobry tok rozumowania (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

dzieki za wyrozumialosc (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




po pierwsze: popelniasz blad, gdyz w petli dla roznych inputów zapodajesz te same id:id=id[$ile]. Dlategosamego kroku, te id bedą identyczne, wiec po id ich nie rozróżnisz

po drugie: weź ty te wszystkie id wsadź do jednego diva, temu divowi nadaj id zależne od $ile, tylko juz nie rob tablicy, a poprotstu dopisz te $ile do id. potem do funkcji show() zapodawa te $ile i bedzie git. ww skrocie:
  1. <?php
  2.  
  3. for($ile=0;$ile<=7;$ile++){
  4.  
  5.  echo "<input type='checkbox' onchange='show($ile)' name='dni[]' value=$tablica[$ile]>";
  6. echo "<div id='div_$ile'>tutaj te twoje inputy</div>";
  7.  
  8.  }
  9.  
  10. ?>


funcja js poza pętlą:
Kod
<script language='JavaScript'>

function show(nr)
{
obj=document.getElementById('div_'+nr);
obj.style.display='';
}

</script>

A zeby pokazywac jak checkboxa zaznaczysz, to tez w linku bylo.
Go to the top of the page
+Quote Post
adeq_PL
post
Post #7





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 25.01.2006
Skąd: Oświęcim

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


nospor zrobilem jak kazales ale nadal mi wyskakuje jakis blad :/

Moglbys jeszcze raz na to looknac?

  1. <?php
  2. echo "<script language='JavaScript'>
  3.  
  4. function show(0)
  5. {
  6.  obj=document.getElementById('div_0');
  7.  obj.style.display='';
  8. }
  9. function show(1)
  10. {
  11.  obj=document.getElementById('div_1');
  12.  obj.style.display='';
  13. }
  14. function show(2)
  15. {
  16.  obj=document.getElementById('div_2');
  17.  obj.style.display='';
  18. }
  19. function show(3)
  20. {
  21.  obj=document.getElementById('div_3');
  22.  obj.style.display='';
  23. }
  24. function show(4)
  25. {
  26.  obj=document.getElementById('div_4');
  27.  obj.style.display='';
  28. }
  29. function show(5)
  30. {
  31.  obj=document.getElementById('div_5');
  32.  obj.style.display='';
  33. }
  34. function show(6)
  35. {
  36.  obj=document.getElementById('div_6');
  37.  obj.style.display='';
  38. }
  39. function show(7)
  40. {
  41.  obj=document.getElementById('div_7');
  42.  obj.style.display='';
  43. }
  44.  
  45.  </script>";
  46.  
  47.  
  48. $tablica = array ("Pn.-Pt.", "Poniedziałek", "Wtorek", "&para;roda", "Czwatrek", "Pi&plusmn;tek", "Sobota", "Niedziela");
  49.  
  50.  echo "<table width=350 cellpadding='1' cellspacing='0'>";
  51.  
  52. for($ile=0;$ile<=7;$ile++){
  53.  
  54.  echo "<tr><td align='left'>";
  55.  
  56.  echo "<input type='checkbox' onClick='show($ile)' name='dni[]' value=$tablica[$ile]>
  57.  <font class=edytuj>$tablica[$ile]</font>
  58.  
  59.  </td><td>";
  60.  
  61. echo "<div id='div_$ile' style='display:none'>
  62. <font class=edytuj> od: </font><input type='text' size='1' name='godzod[$ile]' maxlength='2'> 
  63. <font class=edytuj> : </font><input type='text' ' size='1' name='minod[$ile]' maxlength='2'>
  64. <font class=edytuj> do: </font><input type='text' size='1' name='godzdo[$ile]' maxlength='2'>
  65. <font class=edytuj> : </font><input type='text' size='1' name='mindo[$ile]' maxlength='2'>
  66. </div>";
  67.  
  68. echo "</td></tr>";
  69.  
  70.  }
  71.  
  72.  
  73. echo "</table>";
  74.  
  75. ?>


co robie zle?
Go to the top of the page
+Quote Post
nospor
post
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




wyraźnie ci napisalem, ze funckja show() ma byc poza pętlą. Sądząc po twoim kodzie albo tego nie doczytales, albo to źle zrozumiales i dales ją pozapętlą, ale ręcznie sam nastukales ich x-nascie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Ma byc kedna funkcja show i tylko jedna. tak jak ci podalem.

Cytat
ale nadal mi wyskakuje jakis blad :
Na przyszlość podziel sie z nami tym bledem (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
adeq_PL
post
Post #9





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 25.01.2006
Skąd: Oświęcim

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


WIELKIE dzieki nospor!!!

Jestes naprawde swietnym programista i nauczycielem dzieki (IMG:http://forum.php.pl/style_emoticons/default/exclamation.gif) !!!


A funkce odwrotna zrobilem juz sam na podstawie podanego linku (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)


Kod
<script language='JavaScript'>
          function show(nr)
  {
      obj=document.getElementById('div_'+nr);
      objCheck=document.getElementById('check_'+nr);
  if (objCheck.checked)
      obj.style.display='';
  else
      obj.style.display='none';
  }


       </script>


pozdrawiam (IMG:http://forum.php.pl/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: 22.08.2025 - 21:41