Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][jQuery] funkcja zaznaczajaca checkboxy
raval
post
Post #1





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 1.04.2011

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


Witam,

chcę napisać funkcję w jQuery, która po zaznaczeniu checkoxa "rodzica", zostana zaznaczone wszystkie pozostałe checkboxy mu podlegające.

Moja funkcja t:

  1. $('#select_all').click(function()
  2. {
  3. if($(this).is(':checked'))
  4. {
  5. $('#id').attr(':checked',true)
  6. }
  7. else
  8. {
  9. $('#id').attr(':checked',false)
  10. }
  11.  
  12. });


a kod php:

  1. <input type="checkbox" id="select_all">Select All
  2.  
  3. ...
  4.  
  5. {section name=j loop=$produkt}
  6.  
  7. {if $kategorie[i]['id'] eq $produkt[j]['id']}
  8. <tr>
  9. <td>
  10.  
  11. {if $produkt[j]['id_offer'] eq $zaznaczone[j]['id']}
  12. <input type="checkbox" checked name="id[]" id="id" value="{$produkt[j]['id_offer']}"/>
  13. {else}
  14. <input type="checkbox" name="id[]" id="id" value="{$produkt[j]['id_offer']}"/>
  15. {/if}
  16. {$produkt[j]['name']}
  17.  
  18. </td>
  19. </tr>
  20. {/if}
  21. {/section}
  22.  
  23. ...


Niestety po zaznaczeniu checkboxa SELECT_ALL nic się nie dzieje, czy mógłbym prosić o jakąś pomoc? :X
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
raval
post
Post #2





Grupa: Zarejestrowani
Postów: 100
Pomógł: 0
Dołączył: 1.04.2011

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


  1. <script type="text/javascript">
  2.  
  3.  
  4. $(document).ready(
  5. function()
  6. {
  7.  
  8. $("table.EditDel tr:odd").addClass("tlo2");
  9. $("table.EditDel tr:even").addClass("tlo1");
  10.  
  11. $("tr#wybor td h4").next("#rozwin:visible").hide();
  12.  
  13. $("tr#wybor td").children("h4").click(
  14. function()
  15. {
  16. $(this).next("#rozwin").show(200);
  17. $("tr#wybor td h4").not(this).next("#rozwin:visible").hide();
  18. });
  19.  
  20.  
  21.  
  22. $("input:checkbox#select_all").click(function()
  23. {
  24. var id = $(this).val();
  25. $('.'+id).attr('checked',this.checked);
  26.  
  27.  
  28. });
  29.  
  30.  
  31. });
  32. </script>
  33.  
  34. </head>
  35. <body>
  36.  
  37. <form name="produkty" id="produkty" method="POST" action="{$des}?id={$id_store}">
  38. <table rules="rows" width="500">
  39. <th >Kategorie sklepu</th>
  40.  
  41. {section name=i loop=$kategorie}
  42. <tr id="wybor">
  43. <td><h4 style="cursor:pointer;display:inline;">{$kategorie[i]['name']}</h4>
  44.  
  45. <div id="rozwin">
  46.  
  47. <input type="checkbox" id="select_all" value="{$smarty.section.i.index}">Select All
  48. <hr>
  49.  
  50. <table>
  51.  
  52. {section name=j loop=$produkt}
  53.  
  54. {if $kategorie[i]['id'] eq $produkt[j]['id']}
  55. <tr>
  56. <td>
  57.  
  58. {if $produkt[j]['id_offer'] eq $zaznaczone[j]['id']}
  59. <input type="checkbox" checked name="id[]" class="{$smarty.section.i.index}" value="{$produkt[j]['id_offer']}"/>
  60. {else}
  61. <input type="checkbox" name="id[]" class="{$smarty.section.i.index}" value="{$produkt[j]['id_offer']}"/>
  62. {/if}
  63. {$produkt[j]['name']}
  64.  
  65. {*$smarty.section.i.index*}
  66. </td>
  67. </tr>
  68. {/if}
  69. {/section}
  70. </table>
  71. <hr>
  72. </div>
  73. </td>
  74.  
  75.  
  76. </tr>
  77.  
  78. {/section}
  79. <tr>
  80. <td colspan="2" align="middle">
  81. <input type="submit" value="Zapisz produkty" />
  82. </td>
  83. </tr>
  84. </table>
  85. </form>
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 8.10.2025 - 21:20