PHP, select multiple y Javascript

From: Date: Thu, 13 Feb 2003 19:24:38 +0000
Subject: PHP, select multiple y Javascript
Groups: php.general.es 
Request: Send a blank email to general-es+get-32345@lists.php.net to get a copy of this message
Hola listeros: Tengo un problema que está relacionado con Javascript y php, les cuento: Estoy tratando de hacer una selección múltiple, que esta relacionada con javascript, por lo cual aparentemente la opción de enviar los datos a través de <select multiple name="lista2[]">, no funciona ya que en el Javascript necesito hacer referencia al nombre de la lista y no anda al tener "[]" incluido. Por otro lado encontré en la lista algo que quizás me serviría, pero no logro hacer que funcione: function pasavalor() { r = document.nombredelform // Recorre el form for(i=0;i<r.nombredelselect.options.length;i++) { if(r.nombredelselect.options[i].selected == true) r.nombrecampooculto.value = r.nombredelsect.options[i].value + '|' } // Manda el form r.submit() } Les envío el código de javascript, por las dudas no me expliqué bien (opciones múltiples se armarían a través de consultas a Mysql, pero lo simplifiqué para que sea mas entendible) Desde ya muchas gracias <HEAD> <SCRIPT LANGUAGE="JavaScript"> function move(fbox, tbox) { var arrFbox = new Array(); var arrTbox = new Array(); var arrLookup = new Array(); var i; for (i = 0; i < tbox.options.length; i++) { arrLookup[tbox.options[i].text] = tbox.options[i].value; arrTbox[i] = tbox.options[i].text; } var fLength = 0; var tLength = arrTbox.length; for(i = 0; i < fbox.options.length; i++) { arrLookup[fbox.options[i].text] = fbox.options[i].value; if (fbox.options[i].selected && fbox.options[i].value != "") { arrTbox[tLength] = fbox.options[i].text; tLength++; } else { arrFbox[fLength] = fbox.options[i].text; fLength++; } } arrFbox.sort(); arrTbox.sort(); fbox.length = 0; tbox.length = 0; var c; for(c = 0; c < arrFbox.length; c++) { var no = new Option(); no.value = arrLookup[arrFbox[c]]; no.text = arrFbox[c]; fbox[c] = no; } for(c = 0; c < arrTbox.length; c++) { var no = new Option(); no.value = arrLookup[arrTbox[c]]; no.text = arrTbox[c]; tbox[c] = no; } } // End --> </script> </HEAD> <BODY> <form action="1002.php" method="post" name="combo_box"> <table><tr><td> <select multiple size="5" name="lista1" style="width:150"> <option value="1">dato 1</option> <option value="2">dato 2</option> <option value="3">dato 3</option> <option value="4">dato 4</option> </select> </td> <td align="center" valign="middle"> <input type="button" onClick="move(this.form.lista2,this.form.lista1)" value="<<"> <input type="button" onClick="move(this.form.lista1,this.form.lista2)" value=">>"> </td> <td> <select multiple size="5" name="lista2" style="width:150"> <option value="5">dato 5</option> <option value="6">dato 6</option> <option value="7">dato 7</option> </select> </td></tr></table> <input type="submit" name="Submit" value="Enviar" onSubmit="pasavalor()"> </form> Aparentemente me faltaría que se seleccionaran los datos automáticamente antes de ser enviado el formulario, pero mas que nada, me preocupa no poder enviar los datos a la página php PD: volví a mandar el mail pero sin el [OT], ya que pensándolo bien, es un problema que está relacionado directamente con PHP y quizás alguien que tenga la respuesta decidieran no responderlo por otro lado pienso que puede ser útil para otro listero.

« previous php.general.es (#32345) next »