Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [jQuery] Radio buttony - wylaczanie pozostalych po kliknieciu na jeden z nich
swiezak
post
Post #1





Grupa: Zarejestrowani
Postów: 159
Pomógł: 0
Dołączył: 21.08.2011

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


Mam taki oto formularz:
  1. <form id="jsForm" action="" method="post">
  2. <div class="panel-group" id="accordion">
  3. <div class="panel panel-primary">
  4. <div class="panel-heading">
  5. <h4 class="panel-title">
  6. <a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
  7. <i class="fa fa-caret-right"></i> {% trans %}Odbiór osobisty{% endtrans %}</a>
  8. </h4>
  9. </div>
  10. <div id="collapse1" class="panel-collapse collapse in">
  11. <div class="panel-body">
  12. <div class="form-group">
  13. <input class="radio_btn" type="radio" checked="checked" name="payment[1]" value="1"> {% trans %}Płatność gotówką{% endtrans %}
  14. </label>
  15. <input class="radio_btn" type="radio" name="payment[1]" value="2"> {% trans %}Płatność przelewem z góry{% endtrans %}
  16. </label>
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="panel panel-primary">
  22. <div class="panel-heading">
  23. <h4 class="panel-title">
  24. <a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
  25. <i class="fa fa-caret-right"></i> {% trans %}Kurier{% endtrans %}</a>
  26. </h4>
  27. </div>
  28. <div id="collapse2" class="panel-collapse collapse">
  29. <div class="panel-body">
  30. <div class="form-group">
  31. <input class="radio_btn" type="radio" name="payment[2]" value="3"> {% trans %}Płatność za pobraniem{% endtrans %}
  32. </label>
  33. <input class="radio_btn" type="radio" name="payment[2]" value="2"> {% trans %}Płatność przelewem z góry{% endtrans %}
  34. </label>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </form>


Chcialbym uzyskac efekt, aby po kliknieciu na wybrany radio buttom pozostale nie byly zaznaczone. W tej chwili istnieje mozliwosc ustawienia 2 radio buttonow w tym samym czasie.
Jak tego dokonac?

Probuje w ten sposob, ale nie dziala:
  1. $('#accordion').on('hidden.bs.collapse', function (e) {
  2. $(e.target).find('input[type=radio]:first').prop("checked", true)
  3. });



Prosze o pomoc.
Go to the top of the page
+Quote Post
ShaggyAG
post
Post #2





Grupa: Zarejestrowani
Postów: 111
Pomógł: 11
Dołączył: 12.10.2014
Skąd: Tarnów

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


Daj i im taki sam atrybut name

ok ide po kawe.
Sorry

Ten post edytował ShaggyAG 18.02.2016, 08:53:41
Go to the top of the page
+Quote Post
swiezak
post
Post #3





Grupa: Zarejestrowani
Postów: 159
Pomógł: 0
Dołączył: 21.08.2011

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


No wlasnie tu jest problem, bo payment[1] przechowuje id sposobu dostawy - w tym wypadku 1.
Go to the top of the page
+Quote Post
kapslokk
post
Post #4





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


W takim razie rozbij to na 2 grupy radio
1 bedzie wybierala sposb dostawy a 2 sposob platnosci
Go to the top of the page
+Quote Post
swiezak
post
Post #5





Grupa: Zarejestrowani
Postów: 159
Pomógł: 0
Dołączył: 21.08.2011

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


A gdyby do kazdego inputa dodac zdarzenie onclick i w jakis magiczny sposob wylaczac pozostale radio buttony?

Cos w rodzaju:
  1. <input class="radio_btn" type="radio" checked="checked" name="payment[1]" value="1" onclick="disable('...');">

Go to the top of the page
+Quote Post
rad11
post
Post #6





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

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


Rozbij to na grupy i mniej wiecej coś takiego:

  1. <input name="payment[1]" type="radio" class="groupRadio first"/>
  2. <input name="payment[1]" type="radio" class="groupRadio first"/>
  3.  
  4. <input name="payment[2]" type="radio" class="groupRadio second"/>
  5. <input name="payment[2]" type="radio" class="groupRadio second"/>

  1. $(".groupRadio").on('click', function () {
  2. switch ($(this).hasClass("first")) {
  3. case true:
  4. $(".second").removeAttr("checked");
  5. break;
  6. case false:
  7. $(".first").removeAttr("checked");
  8. break;
  9. }
  10. });

Go to the top of the page
+Quote Post
swiezak
post
Post #7





Grupa: Zarejestrowani
Postów: 159
Pomógł: 0
Dołączył: 21.08.2011

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


Dziekuje serdecznie za poswiecony czas i pomoc.

Dla zainteresowanych.
W przypadku trzech grup radio buttonow mozna wykorzystac ponizszy kod:
  1. $(".groupRadio").on('click', function () {
  2. switch ($(this).hasClass("first")) {
  3. case true:
  4. $(".second").removeAttr("checked");
  5. $(".third").removeAttr("checked");
  6. break;
  7. case false:
  8. $(".first").removeAttr("checked");
  9. if ($(this).hasClass("second")) {
  10. $(".third").removeAttr("checked");
  11. }
  12. if ($(this).hasClass("third")) {
  13. $(".second").removeAttr("checked");
  14. }
  15. break;
  16. }
  17. });



Pozdrawiam.

Ten post edytował swiezak 18.02.2016, 12:13:22
Go to the top of the page
+Quote Post
trueblue
post
Post #8





Grupa: Zarejestrowani
Postów: 6 809
Pomógł: 1828
Dołączył: 11.03.2014

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


Dla dowolnej liczby grup:


  1. <input name="payment[1]" type="radio" class="groupRadio" />
  2. <input name="payment[1]" type="radio" class="groupRadio" />
  3.  
  4. <input name="payment[2]" type="radio" class="groupRadio" />
  5. <input name="payment[2]" type="radio" class="groupRadio" />
  6.  
  7. <input name="payment[3]" type="radio" class="groupRadio" />
  8. <input name="payment[3]" type="radio" class="groupRadio" />
  9.  
  10. $(".groupRadio").on('click', function() {
  11. $('.groupRadio:not([name="'+$(this).attr('name')+'"])').removeAttr("checked");
  12. });
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.12.2025 - 06:12