Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Przenoszenie elementów pomiędzy selectami, no właśnie, jak to zrobić ?!
tiraeth
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

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


Witam, mam problem gdyż piszę system downloadu, i jedną z rzeczy jaka musi być w nim zawarta to wybór plików, które mogą być uploadowane w danej kategorii. Typy tych plików muszą być wybierana podczas tworzenia kategorii.
No i teraz chciałbym zrobić, żeby to wyglądało tak:
Kod
Wybór plików:                     Akceptowane typy:
+------------------+              +------------------+
| Audio            |              |                  |
|   .mp3           |              |                  |
|   .wav           |              |                  |
|   .ogg           |    ------    |                  |
|   .wma           |   |  >>  |   |                  |
|                  |    ------    |                  |
| Video            |              |                  |
|   .avi           |    ------    |                  |
|   .dat           |   |  <<  |   |                  |
|   .mpeg          |    ------    |                  |
|   .wmv           |              |                  |
|                  |              |                  |
|    Wszystkie     |              |                  |
|                  |              |                  |
|                  |              |                  |
+------------------+              +------------------+


Chodzi mi o te dwa przyciski >> i << chciałbym aby po nacisnięciu tego pierwszego, zaznaczony element (option) z select'u select1 został dodany jako nowa pozycja do selectu obok - select2, oraz usunięty z select1. Przycisk drugi miałby robić to samo ale w drugą stronę (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Zastanawiam się jak to zrobić (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif) Proszę o pomoc...

Aha, jeszcze nie wiem jak po nacisnięciu przycisku BUTTON zrobić tak aby zaznaczyło cały select2, aby wybrane typy zostały przesłane poprzez $_POST, co do wyslania formularza z BUTTON to wiem jak to zrobić...

Ten post edytował Tiraeth 6.04.2005, 12:33:24
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
phpion
post
Post #2





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Odswiezam.
Czy daloby sie zmodyfikowac skrypt tak, zeby przenosil dane z jednego pola do drugiego we wskazane miejsce? Tj. np z s1 za aktualnie zaznaczony element w s2?
EDIT:
I moze jeszcze jedna modyfikacja: zeby obslugiwal pola multiple czyli pozwalal na przenoszenie kilku wartosci na raz. Nie wiem nawet pod jakim haslem szukac - prosilbym o nakierowanie mnie.

Ssss jednak na nic mi sie to przyda :/
Moze przy okazji: czy daloby sie przeslac do skryptu php wszsytkie dane (obojetnie czy indexy czy wartosci) znajdujace sie w drugim selectcie? Zakaldam ze to bylaby jakas funkcja przypisujaca do zmiennej (np. stringa) wszystkie wartosci.

=============================================

Znalazlem odpowiednie skrypciki, polaczylem je w calosc i PRAWIE dzialaja poprawnie. Mozna przenosic po kilka pozycji na raz, mozna dodawac dane we wskazane miejsce, mozna dane przeslac do php (funkcja wyslij()). Jednak jest pewien maly problem. Otoz przenoszenie danych powoduje przeniesienie wskazanych danych + pustych pol w ilosci rownej liczbie przenoszonych pol. Nie wiem jak sie tego pozbyc. Przy wysylaniu danych przez wyslij() te puste pola nie sa juz pokazywane. Mialby ktos jakis pomysl?
  1. <?xml version="1.0" encoding="iso-8859-2"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5. <title>Przenoszenie miedzy selectami</title>
  6. <meta name="GENERATOR" content="Quanta Plus" />
  7. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
  8. <style type="text/css">
  9. /* <![CDATA[ */
  10.  
  11. /* ]]> */
  12. </style>
  13. <script language="javascript" type="text/javascript">
  14. /* <![CDATA[ */
  15. var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
  16.  
  17. function wyslij(theSel)
  18. {
  19. var selLength = theSel.length;
  20. var output = '';
  21.  
  22. for (i=0; i<selLength; i++)
  23. {
  24. output += theSel.options[i].text + ', ';
  25. }
  26.  
  27. alert(output);
  28. }
  29.  
  30. function appendOldSchool(theSel, newText, newValue)
  31. {
  32. if (theSel.length == 0) {
  33. var newOpt1 = new Option(newText, newValue);
  34. theSel.options[0] = newOpt1;
  35. theSel.selectedIndex = 0;
  36. } else if (theSel.selectedIndex != -1) {
  37. var selText = new Array();
  38. var selValues = new Array();
  39. var selIsSel = new Array();
  40. var newCount = -1;
  41. var newSelected = -1;
  42. var i;
  43. for(i=0; i<theSel.length; i++)
  44. {
  45. newCount++;
  46. selText[newCount] = theSel.options[i].text;
  47. selValues[newCount] = theSel.options[i].value;
  48. selIsSel[newCount] = theSel.options[i].selected;
  49.  
  50. if (newCount == theSel.selectedIndex) {
  51. newCount++;
  52. selText[newCount] = newText;
  53. selValues[newCount] = newValue;
  54. selIsSel[newCount] = false;
  55. newSelected = newCount - 1;
  56. }
  57. }
  58. for(i=0; i<=newCount; i++)
  59. {
  60. var newOpt = new Option(selText[i], selValues[i]);
  61. theSel.options[i] = newOpt;
  62. theSel.options[i].selected = selIsSel[i];
  63. }
  64. }
  65. }
  66.  
  67. function addOption(theSel, theText, theValue)
  68. {
  69. var newOpt = new Option(theText, theValue);
  70. var selLength = theSel.length;
  71. theSel.options[selLength] = newOpt;
  72. }
  73.  
  74. function deleteOption(theSel, theIndex)
  75. {
  76. var selLength = theSel.length;
  77. if(selLength>0)
  78. {
  79. theSel.options[theIndex] = null;
  80. }
  81. }
  82.  
  83. function moveOptions(theSelFrom, theSelTo)
  84. {
  85.  
  86. var selLength = theSelFrom.length;
  87. var selectedText = new Array();
  88. var selectedValues = new Array();
  89. var selectedCount = 0;
  90.  
  91. var i;
  92.  
  93. // Find the selected Options in reverse order
  94. // and delete them from the 'from' Select.
  95. for(i=selLength-1; i>=0; i--)
  96. {
  97. if(theSelFrom.options[i].selected)
  98. {
  99. selectedText[selectedCount] = theSelFrom.options[i].text;
  100. selectedValues[selectedCount] = theSelFrom.options[i].value;
  101. deleteOption(theSelFrom, i);
  102. selectedCount++;
  103. }
  104. }
  105.  
  106. // Add the selected text/values in reverse order.
  107. // This will add the Options to the 'to' Select
  108. // in the same order as they were in the 'from' Select.
  109. for(i=selectedCount-1; i>=0; i--)
  110. {
  111. appendOldSchool(theSelTo, selectedText[i], selectedValues[i]);
  112. }
  113.  
  114. if(NS4) history.go(0);
  115. }
  116. /* ]]> */
  117. </script>
  118. </head>
  119.  
  120. <form action="selecty.php" method="post">
  121. <table border="0">
  122. <tr>
  123. <td>
  124. <select name="sel1" size="30" multiple="multiple" style="width: 200px;">
  125. <option value="1">Left1</option>
  126. <option value="2">Left2</option>
  127. <option value="3">Left3</option>
  128. <option value="4">Left4</option>
  129. <option value="5">Left5</option>
  130. <option value="6">Right1</option>
  131. <option value="7">Right2</option>
  132. <option value="8">Right3</option>
  133. <option value="9">Right4</option>
  134. <option value="10">Right5</option>
  135. </select>
  136. </td>
  137. <td align="center" valign="middle">
  138. <input type="button" value="--&gt;"
  139. onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
  140. <input type="button" value="&lt;--"
  141. onclick="moveOptions(this.form.sel2, this.form.sel1);" />
  142. </td>
  143. <td>
  144. <select name="sel2" size="30" multiple="multiple" style="width: 200px;">
  145. </select>
  146. </td>
  147. </tr>
  148. <input type="button" value="Wyslij" onclick="wyslij(this.form.sel2);" />
  149. </form>
  150.  
  151. </body>
  152. </html>


Ten post edytował phpion.com 1.11.2006, 11:44:55
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: 5.10.2025 - 01:50