Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] Select
Puzi
post 28.08.2008, 13:40:01
Post #1





Grupa: Zarejestrowani
Postów: 231
Pomógł: 17
Dołączył: 26.08.2007

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


Witam,
Mam mały problem z javascript...
Mam taki skrypt java:
  1. <script language="JavaScript" type="text/javascript">
  2. function checkType(val) {
  3.  
  4. if( val == 'Tabela' ) {
  5.  
  6. document.getElementById('element01').style.display = 'table-row';
  7. document.getElementById('element01').style.visibility = 'visible';
  8. document.getElementById('element02').style.display = 'none';
  9. document.getElementById('element02').style.visibility = 'hidden';
  10. document.getElementById('element03').style.display = 'none';
  11. document.getElementById('element03').style.visibility = 'hidden';
  12. document.getElementById('element04').style.display = 'table-row';
  13. document.getElementById('element04').style.visibility = 'visible';
  14.  
  15. } else {
  16. document.getElementById('element01').style.display = 'none';
  17. document.getElementById('element01').style.visibility = 'hidden';
  18. document.getElementById('element02').style.display = 'table-row';
  19. document.getElementById('element02').style.visibility = 'visible';
  20. document.getElementById('element03').style.display = 'table-row';
  21. document.getElementById('element03').style.visibility = 'visible';
  22. document.getElementById('element04').style.display = 'none';
  23. document.getElementById('element04').style.visibility = 'hidden';
  24. }
  25. }


oraz taki skrypt php
  1. <?php
  2. $tresc_zapytania = "SELECT * FROM `cos_tam` WHERE `id`='{$id}'";
  3. $zapytanie = mysql_query($tresc_zapytania);
  4.  
  5. $wiersz = mysql_fetch_row($zapytanie);
  6.  
  7. echo '
  8. <center>
  9. <form action="cos_tam.php?id='.$wiersz[0].'" method="post">
  10. <table cellpadding="0" id="tabela" width="100%">
  11. <tr>
  12. <td id="top_4" width="120">&nbsp;Rodzaj</td>
  13. <td id="top_3" width="580">&nbsp;&nbsp;<select name="rodzaj" onChange="checkType(this.value);">';
  14. if($wiersz[2] == 'Tabela')
  15. {
  16. echo '
  17. <option value="Inne">Cos innego</option>
  18. <option value="Tabela" selected>Tabela</option>
  19. ';
  20. }
  21. else 
  22. {
  23. echo '
  24. <option value="Inne" selected>Cos innego</option>
  25. <option value="Tabela">Tabela</option>
  26. ';
  27. }
  28.  
  29. echo '
  30. </select>
  31. </td>
  32. </tr>
  33. <tr id="element01" style="visibility:hidden; display:none;">
  34. <td id="top_4" width="120">&nbsp;Tabela</td>
  35. <td id="top_3" width="580">&nbsp;&nbsp; Jakiś element tabeli</td>
  36. </tr>
  37. <tr id="element04" style="visibility:hidden; display:none;">
  38. <td id="top_4" width="120">&nbsp;Tabela</td>
  39. <td id="top_3" width="580">&nbsp;&nbsp; Jakiś element tabeli</td>
  40. </tr>
  41. <tr id="element02">
  42. <td colspan="2" id="top_4">&nbsp;Cos innego</td>
  43. </tr>
  44. <tr id="element03">
  45. <td class="top_3" colspan=2>&nbsp;&nbsp; Cos innego</td>
  46. </tr>
  47. </table>
  48. <br>
  49. <center>
  50. <input type="submit" value="Zapisz zmiany" class="wyloguj">
  51. </form>
  52. </center>
  53. ';
  54. ?>


I ma mam następujący problem... Jak w bazie ustawione jest, że rodzaj to "Tabela" to i tak po wejściu na stronę nadal pokazuje elementu tabeli, które mają należec do rodzaju "Coś tam innego" a powinno pokazywać elementy do "Tabela"

Proszę o pomoc

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
lord_t
post 28.08.2008, 17:37:41
Post #2





Grupa: Zarejestrowani
Postów: 603
Pomógł: 131
Dołączył: 24.07.2007
Skąd: Górny Śląsk

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


A czemu miałoby pokazać elementy tabeli, skoro są ukryte stylem? A Twój Js się wykonuje dopiero po zmianie tego co jest w select.

W php musisz określić co ma być hidden a co nie - tzn czy elem.01 i 04 czy 02 i 03.

PS. Nast. razem nim wyślesz posta, to go przeczytaj i pomyśl, czy to się da zrozumieć.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 14:05