php Listboxen auswerten

xxxGURUxxx

Grünschnabel
Hi,

ich finde nirgends einen Code mit dem ich eine komplette Listbox aller ITEMS in einen Array schreibe und dann jeden einzelnen eintrag wieder z.b. mit einem ECHO ausgebe


hat jemand von euch Info oder Hinweis

anbei mein Code dort sind 2 Listboxen mit den Buttons kann ich von einer Listbox zur andren ITEMS verschieben mit den Speichern Button möchte ich nun die Komplette rechte Listbox abfragen

Danke

Mario

PHP:
<html>    
<head>
<?php
     var_dump($_POST['ToLB']);
     
@$ToLB1= $_POST['ToLB'];
if( is_array($ToLB1)){
while (list ($key, $val) = each ($ToLB1)) {
echo "$val <br>";
}
}else{echo "not array";}      
     
?>



<script language="javascript"> 
function move(tbFrom, tbTo) 
{
 var arrFrom = new Array(); var arrTo = new Array(); 
 var arrLU = new Array();
 var i;
 for (i = 0; i < tbTo.options.length; i++) 
 {
  arrLU[tbTo.options[i].text] = tbTo.options[i].value;
  arrTo[i] = tbTo.options[i].text;
 }
 var fLength = 0;
 var tLength = arrTo.length;
 for(i = 0; i < tbFrom.options.length; i++) 
 {
  arrLU[tbFrom.options[i].text] = tbFrom.options[i].value;
  if (tbFrom.options[i].selected && tbFrom.options[i].value != "") 
  {
   arrTo[tLength] = tbFrom.options[i].text;
   tLength++;
  }
  else 
  {
   arrFrom[fLength] = tbFrom.options[i].text;
   fLength++;
  }
}

tbFrom.length = 0;
tbTo.length = 0;
var ii;

for(ii = 0; ii < arrFrom.length; ii++) 
{
  var no = new Option();
  no.value = arrLU[arrFrom[ii]];
  no.text = arrFrom[ii];
  tbFrom[ii] = no;
}

for(ii = 0; ii < arrTo.length; ii++) 
{
 var no = new Option();
 no.value = arrLU[arrTo[ii]];
 no.text = arrTo[ii];
 tbTo[ii] = no;
}
}
</script>
</head>

<body>
<hr />  
<form name="combo_box" method="post" >
<table><tr><td>
<select size="10" multiple="multiple" name="FromLB" style="width:150">
  <option value="one">one</option>
  <option value="two">two</option>
  <option value="three">three</option>
  <option value="four">four</option>
  <option value="five">five</option>
  <option value="six">six</option>
  <option value="seven">seven</option>
  <option value="eight">eight</option>
  <option value="nine">nine</option>
  <option value="ten">ten</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.FromLB,this.form.ToLB)" value="->"><br />
<input type="button" onClick="move(this.form.ToLB,this.form.FromLB)" value="<-">
</td>

<td>
  <select size="10" name="ToLB" style="width:150"></select>
</td></tr></table>
</form>
<hr />

		<input type="submit" name="Speichern" value="Speichern" style="background-color: #CCCCCC; color: #666666; height: 50; width: 300; font-family: Arial; font-size: 15pt" onclick="self.location.href='test_listbox.php'">

</body>
</html>
 
So in etwa würde ich sagen:

Javascript:
<script language="javascript" type="text/javascript">
function test () {

var anzahl = document.getElementById("liste").length;
var werte = new Array;

for (a = 0; a < anzahl; a++) {
    werte.push(document.getElementById("liste")[a].value);
}

}
</script>
HTML:
<select name="liste" size="3" id="liste">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
</select>
<br />
<a href="#" onclick="test();">Test</a>
 
http://jsfiddle.net/2UAAR/
HTML:
<div>
  <select size="10" multiple="multiple" id="left-list" style="width:150px"> 
    <option value="one">one</option> 
    <option value="two">two</option> 
    <option value="three">three</option> 
    <option value="four">four</option> 
    <option value="five">five</option> 
    <option value="six">six</option> 
    <option value="seven">seven</option> 
    <option value="eight">eight</option> 
    <option value="nine">nine</option> 
    <option value="ten">ten</option> 
  </select> 
  <select size="10" id="right-list" style="width:150px" multiple="multiple"></select>
</div>
<div>
  <button id="move-to-left-list">nach links</button>
  <button id="move-to-right-list">nach rechts</button>
</div>?
Code:
document.getElementById('move-to-left-list').addEventListener('click', function () {
  var left_list  = document.getElementById('left-list');
  var right_list = document.getElementById('right-list');
  
  for(i = 0; i < right_list.options.length; ++i) {
    if(right_list.options[i].selected === true) {
      left_list.appendChild(right_list.options[i].cloneNode(true));
      right_list.removeChild(right_list.options[i]);
      --i;
    }
  } 
}, false);
document.getElementById('move-to-right-list').addEventListener('click', function () {
  var left_list  = document.getElementById('left-list');
  var right_list = document.getElementById('right-list');
  
  for(i = 0; i < left_list.options.length; ++i) {
    if(left_list.options[i].selected === true) {
      right_list.appendChild(left_list.options[i].cloneNode(true));
      left_list.removeChild(left_list.options[i]);
      --i;
    }
  } 
}, false);
 
Zurück