Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Zaznacz wszystkie (name[], jeden button)
8_pasarzer_NOSTR...
post 5.12.2012, 10:44:32
Post #1





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 5.11.2009

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


Kto pomoże przerobić kod aby był jeden przycisk (Zaznacz wszystko / Odznacz wszystko)
Podaje kod, działający (IE,Fox,Chrome):

  1. <script LANGUAGE="JavaScript">
  2. function SetValues(Form, CheckBox, Value)
  3. {
  4. var objCheckBoxes = document.forms[Form].elements[CheckBox];
  5. var countCheckBoxes = objCheckBoxes.length;
  6. for(var i = 0; i < countCheckBoxes; i++)
  7. objCheckBoxes[i].checked = Value;
  8. }
  9.  
  10.  
  11. <form name="sports" method="post" action="insert.php">
  12. <table border = "1" cellpadding = "5">
  13. <tr>
  14. <td><input type='checkbox' name=boxes[] value='Baseball' />Basketball</td>
  15. <td><input type='checkbox' name=boxes[] value='Basketball' />Basketball</td>
  16. <td><input type='checkbox' name=boxes[] value='Bowling' />Bowling</td>
  17. </tr><tr>
  18. <td><input type='checkbox' name=boxes[] value='Rugby' />Rugby</td>
  19. <td><input type='checkbox' name=boxes[] value='Tennis' />Tennis</td>
  20. <td><input type='checkbox' name=boxes[] value='Valleyball' />Valleyball</td>
  21. </tr></table>
  22. <input type="button" value="Zaznacz wszystkie" onclick="SetValues('sports', 'boxes[]', true);">
  23. <input type="button" value="Odznacz wszystkie" onclick="SetValues('sports', 'boxes[]', false);">


Prośba o przerobienie na jeden przycisk (Zaznacz/Odznacz)
Go to the top of the page
+Quote Post
john_doe
post 5.12.2012, 12:14:38
Post #2





Grupa: Zarejestrowani
Postów: 873
Pomógł: 25
Dołączył: 24.07.2005

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


a tak ?
edytowalem bo mi się coś nie udało. teraz działa - sprawdzilem

  1. function SetValues(Form, CheckBox)
  2. {
  3. var objCheckBoxes = document.forms[Form].elements[CheckBox];
  4. var countCheckBoxes = objCheckBoxes.length;
  5. for(var i = 0; i < countCheckBoxes; i++)
  6. {
  7. if(objCheckBoxes[i].checked)
  8. {
  9. //alert('im in');
  10. objCheckBoxes[i].checked = false;
  11.  
  12. }else { objCheckBoxes[i].checked = true; }
  13. }
  14. }


Ten post edytował john_doe 5.12.2012, 12:26:52
Go to the top of the page
+Quote Post
8_pasarzer_NOSTR...
post 5.12.2012, 13:10:41
Post #3





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 5.11.2009

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


Dzięki Dżony !

A jeszcze jak przerobić by przycisk był taki dla pustych checkboxów :
  1. <input type="button" value="Zaznacz wszystkie" onclick="SetValues('sports', 'boxes[]', true);">


następnie taki, dla zaznaczonych
  1. <input type="button" value="Odznacz wszystkie" onclick="SetValues('sports', 'boxes[]', true);">


Aby się dynamicznie zmieniał.
Go to the top of the page
+Quote Post
john_doe
post 5.12.2012, 13:43:17
Post #4





Grupa: Zarejestrowani
Postów: 873
Pomógł: 25
Dołączył: 24.07.2005

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


  1. function SetValues(Form, CheckBox)
  2. {
  3. var objCheckBoxes = document.forms[Form].elements[CheckBox];
  4. var countCheckBoxes = objCheckBoxes.length;
  5. for(var i = 0; i < countCheckBoxes; i++)
  6. {
  7. if(objCheckBoxes[i].checked)
  8. {
  9.  
  10. objCheckBoxes[i].checked = false;
  11.  
  12. document.getElementById("btn").value="Zaznacz wszystkie";
  13.  
  14. }else {
  15. objCheckBoxes[i].checked = true;
  16. document.getElementById("btn").value="Odznacz wszystkie";
  17. }
  18. }
  19. }


ogólnie trzeci parametr wyrzuć z tych inputów jest niepotrzebny już teraz

Ten post edytował john_doe 5.12.2012, 13:53:02
Go to the top of the page
+Quote Post
8_pasarzer_NOSTR...
post 5.12.2012, 14:32:16
Post #5





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 5.11.2009

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


Przycisk działa ale, zaznacza tylko pierwszy z inputów i usuwa tylko ten wybrany pierwszy z inputów.

Inputy są w pętli, mniej więcej 30.
Go to the top of the page
+Quote Post
john_doe
post 5.12.2012, 14:41:07
Post #6





Grupa: Zarejestrowani
Postów: 873
Pomógł: 25
Dołączył: 24.07.2005

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


coś zepsułeś... nie dodałes id do buttona ( id="btn" )

przeklej sobie to wszystko

  1. <script LANGUAGE="JavaScript">
  2.  
  3. function SetValues(Form, CheckBox)
  4. {
  5. var objCheckBoxes = document.forms[Form].elements[CheckBox];
  6. var countCheckBoxes = objCheckBoxes.length;
  7. for(var i = 0; i < countCheckBoxes; i++)
  8. {
  9. if(objCheckBoxes[i].checked)
  10. {
  11.  
  12. objCheckBoxes[i].checked = false;
  13.  
  14. document.getElementById("btn").value="Zaznacz wszystkie";
  15.  
  16. }else {
  17. objCheckBoxes[i].checked = true;
  18. document.getElementById("btn").value="Odznacz wszystkie";
  19. }
  20. }
  21. }
  22.  
  23.  
  24. <form name="sports" method="post" action="insert.php">
  25.  
  26. <input type='checkbox' name=boxes[] value='Baseball' />Basketball
  27. <input type='checkbox' name=boxes[] value='Basketball' />Basketball
  28. <input type='checkbox' name=boxes[] value='Bowling' />Bowling
  29.  
  30. <input type='checkbox' name=boxes[] value='Rugby' />Rugby
  31. <input type='checkbox' name=boxes[] value='Tennis' />Tennis
  32. <input type='checkbox' name=boxes[] value='Valleyball' />Valleyball
  33.  
  34. <input type="button" id="btn" value="Zaznacz wszystkie" onclick="SetValues('sports', 'boxes[]');" />
  35.  
  36.  
  37. </form>


Ten post edytował john_doe 5.12.2012, 14:50:48
Go to the top of the page
+Quote Post
8_pasarzer_NOSTR...
post 6.12.2012, 08:43:42
Post #7





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 5.11.2009

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


Git majonez,



"POMÓGŁ"
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: 21.09.2024 - 13:03