Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Peguei um código de listbox aqui no fórum, mas estou com algumas dúvidas.
Como faço para pegar todos os dados da segunda listbox???
Já tentei usar o seguinte código:
foreach($_POST['listRight'] as $valor){ echo "$valor<br>";}
Mas não deu certo. Parece que ele só retorna se o valor do listbox estiver selecionado.
Alguém sabe como resolver isso?
Abaixo, o código. A única coisa que eu fiz diferente foi criar um botão e direcionar a página para outra que pega os valores.
<html><head><title>Documento sem título</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><script LANGUAGE="JavaScript">function compareOptionValues(a, b){ var sA = parseInt(a.value, 36); var sB = parseInt(b.value, 36); return sA - sB;}function compareOptionText(a, b){ var sA = parseInt(a.text, 36); var sB = parseInt(b.text, 36); return sA - sB;}function moveDualList(srcList, destList, moveAll){ if ((srcList.selectedIndex == -1) && (moveAll == false)){ return; } newDestList = new Array(destList.options.length); var len = 0; for(len=0; len<destList.options.length; len++){ if(destList.options[ len ] != null ){ newDestList[len] = new Option(destList.options[len].text, destList.options[len].value, destList.options[ len ].defaultSelected, destList.options[len].selected); } } for(var i=0; i<srcList.options.length; i++){ if (srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll)){ newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected ); len++; } } newDestList.sort( compareOptionValues ); for(var j=0; j<newDestList.length; j++){ if(newDestList[j] != null ){ destList.options[ j ] = newDestList[j]; } } for(var i=srcList.options.length - 1; i>=0; i--){ if(srcList.options[i] != null && (srcList.options[i].selected == true || moveAll)){ srcList.options[i] = null; } }}</script></head><body><form ACTION="" METHOD="POST" name="myForm"><table border="0"><tr> <td> <!-- Multiple Select List with 20 rows size and 70 pixels wide --> <!-- Using for SPACING and alignment --> <select multiple size="20" style="width:70" name="listLeft"> <option value="10"> 10 </option> <option value="20"> 20 </option> <option value="30"> 30 </option> <option value="40"> 40 </option> <option value="50"> 50 </option> <option value="A" > A </option> <option value="B" > B </option> <option value="F" > F </option> <option value="X" > X </option> </select> </td> <td><NOBR> <input type="button" style="width:90" onclick="moveDualList(this.form.listLeft, this.form.listRight, false )" value="Add >>"> <BR> <NOBR> <input type="button" style="width:90" onclick="moveDualList(this.form.listRight, this.form.listLeft, false )" value="Add <<"> <BR> <NOBR> <input type="button" style="width:90" onclick="moveDualList(this.form.listLeft, this.form.listRight, true )" value="Add All >>"> <BR> <NOBR> <input type="button" style="width:90" onclick="moveDualList(this.form.listRight, this.form.listLeft, true )" value="Add All <<"> <BR> </NOBR> </td> <td> <select multiple size="20" style="width:70" name="listRight"> <option value="01"> 1 </option> <option value="02"> 2 </option> <option value="03"> 3 </option> <option value="04"> 4 </option> <option value="05"> 5 </option> <option value="D" > D </option> <option value="G" > G </option> <option value="K" > K </option> <option value="Z" > Z </option> <option value="55"> 55 </option> </select> </td></tr></table></form></body></html>Carregando comentários...