problemas con listas y variables
Publicado por Isabel (11 intervenciones) el 24/09/2007 19:44:36
Hola todos, tengo un problema con unas listas y el traspaso de variables espero me puedan colaborar.
El caso es el siguiente:
Tengo en una pagina llamada X.php un formulario para el ingreso de datos de un estudiante, en esta pagina tengo dos listas , en una de ella tengo las materias y en la otra debo pasar las materias que se elsijan en la lista uno . asi por ejemplo:
MATERIAS SELECCIONADAS
Español Ingles
Ingles Religion
Matematicas
Religion
El problema es que no se como hacer para pasar las materias seleccionadas a la lista vacia, y luego pasarlas a la pagina Y.php en la que guardo las materias seleccionadas en una base de datos MYSQL.
Podrian ayudarme?
Yo tengo este codigo en Javascript pero el problema es que no se como capturar las materias escogidas y guardarlas una por una en el registro que corresponda en la base de datos.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Control flags for list selection and sort sequence
// Sequence is on option value (first 2 chars - can be stripped off in form processing)
// It is assumed that the select list is in sort sequence initially
var singleSelect = true; // Allows an item to be selected once only
var sortSelect = true; // Only effective if above flag set to true
var sortPick = true; // Will order the picklist in sort sequence
// Initialise - invoked on load
function initIt() {
var selectList = document.getElementById("SelectList");
var pickList = document.getElementById("PickList");
var pickOptions = pickList.options;
pickOptions[0] = null; // Remove initial entry from picklist (was only used to set default width)
selectList.focus(); // Set focus on the selectlist
}
// Adds a selected item into the picklist
function addIt() {
var selectList = document.getElementById("SelectList");
var selectIndex = selectList.selectedIndex;
var selectOptions = selectList.options;
var pickList = document.getElementById("PickList");
var pickOptions = pickList.options;
var pickOLength = pickOptions.length;
// An item must be selected
if (selectIndex > -1) {
pickOptions[pickOLength] = new Option(selectList[selectIndex].text);
pickOptions[pickOLength].value = selectList[selectIndex].value;
// If single selection, remove the item from the select list
if (singleSelect) {
selectOptions[selectIndex] = null;
}
if (sortPick) {
var tempText;
var tempValue;
// Sort the pick list
while (pickOLength > 0 && pickOptions[pickOLength].value < pickOptions[pickOLength-1].value) {
tempText = pickOptions[pickOLength-1].text;
tempValue = pickOptions[pickOLength-1].value;
pickOptions[pickOLength-1].text = pickOptions[pickOLength].text;
pickOptions[pickOLength-1].value = pickOptions[pickOLength].value;
pickOptions[pickOLength].text = tempText;
pickOptions[pickOLength].value = tempValue;
pickOLength = pickOLength - 1;
}
}
}
}
// Deletes an item from the picklist
function delIt() {
var selectList = document.getElementById("SelectList");
var selectOptions = selectList.options;
var selectOLength = selectOptions.length;
var pickList = document.getElementById("PickList");
var pickIndex = pickList.selectedIndex;
var pickOptions = pickList.options;
if (pickIndex > -1) {
// If single selection, replace the item in the select list
if (singleSelect) {
selectOptions[selectOLength] = new Option(pickList[pickIndex].text);
selectOptions[selectOLength].value = pickList[pickIndex].value;
}
pickOptions[pickIndex] = null;
if (singleSelect && sortSelect) {
var tempText;
var tempValue;
// Re-sort the select list
while (selectOLength > 0 && selectOptions[selectOLength].value < selectOptions[selectOLength-1].value) {
tempText = selectOptions[selectOLength-1].text;
tempValue = selectOptions[selectOLength-1].value;
selectOptions[selectOLength-1].text = selectOptions[selectOLength].text;
selectOptions[selectOLength-1].value = selectOptions[selectOLength].value;
selectOptions[selectOLength].text = tempText;
selectOptions[selectOLength].value = tempValue;
selectOLength = selectOLength - 1;
}
}
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++;
}
}
if (strValues.length == 0) {
alert("No has hecho ninguna selección");
}
else {
alert("Aquí están los valores seleccionados:\r\n" + strValues);
}
}
-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Kathi O'Shea (Kathi.O'[email protected]) -->
<!-- Web Site: http://www.web-savant.com/users/kathi/asp -->
<!-- Begin
function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if ( selectedText=="Svenska A"){
var xy="svenska A"
alert (xy);
<?php
$xy="Svenska A";
?>
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++
}
}
if (strValues.length == 0) {
alert("No has hecho ninguna selección");
}
else {
alert("Aquí están los valores seleccionados:\r\n" + strValues);
}
}
// End -->
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(gris.png);
}
.style2 {color: #FFFFFF}
-->
</style></head>
<body>
<table width="755" border="8" align="center" bordercolor="#FD802C" bgcolor="#FD802C">
<tr>
<td bgcolor="#FFFFFF"><p align="right"><span class="title"><span class="style2">.</span></span><span class="style2">....</span></p>
<p align="center" class="title">REGISTRERA</p>
<form name="choiceForm" method="post" action="prueva.php">
<p> </p>
<p> </p>
<table border=0 width="414">
<tr>
<td valign="top" width=180> <br>
<select name="available" size=10 onchange="moveOver();">
<option value= "Svenska A">Svenska A
<option value= "Svenska B">Svenska B
<option value=3>Actualizaciones de productos
<option value=4>Especificaciones de productos
<option value=5>Historia de pedidos
<option value=6>Estado del pedido
<option value=7>Contactos
<option value=8>Calendario de eventos
<option value=9>Planificación
<option value=10>Notas
</select></td>
<td valign="top" width=43><p> </p>
<p> </p>
<p>
<input name="button2" type="button" style="font-size: 8pt" onClick="removeMe();" value="Eliminar">
</p></td>
<td valign="top" width="151"><font size="2">:</font><br>
<select multiple name="choiceBox" style="width:150;" size="10">
</select></td>
</tr>
<tr>
<td colspan=3 height=10>
<input name="button2" type="button" style="font-size: 8pt" onclick="saveMe();" value="Obtener valores seleccionados"></td>
</tr>
</table>
<p> </p>
<p> </p>
<p><!-- This form is inoperational! Provisional users can't create forms NAME="theform" ID="theform" onSubmit="return false" -->
</p>
<input name="Submit" type="submit" value="Spara">
</form>
</table>
</body>
</html>
El caso es el siguiente:
Tengo en una pagina llamada X.php un formulario para el ingreso de datos de un estudiante, en esta pagina tengo dos listas , en una de ella tengo las materias y en la otra debo pasar las materias que se elsijan en la lista uno . asi por ejemplo:
MATERIAS SELECCIONADAS
Español Ingles
Ingles Religion
Matematicas
Religion
El problema es que no se como hacer para pasar las materias seleccionadas a la lista vacia, y luego pasarlas a la pagina Y.php en la que guardo las materias seleccionadas en una base de datos MYSQL.
Podrian ayudarme?
Yo tengo este codigo en Javascript pero el problema es que no se como capturar las materias escogidas y guardarlas una por una en el registro que corresponda en la base de datos.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Control flags for list selection and sort sequence
// Sequence is on option value (first 2 chars - can be stripped off in form processing)
// It is assumed that the select list is in sort sequence initially
var singleSelect = true; // Allows an item to be selected once only
var sortSelect = true; // Only effective if above flag set to true
var sortPick = true; // Will order the picklist in sort sequence
// Initialise - invoked on load
function initIt() {
var selectList = document.getElementById("SelectList");
var pickList = document.getElementById("PickList");
var pickOptions = pickList.options;
pickOptions[0] = null; // Remove initial entry from picklist (was only used to set default width)
selectList.focus(); // Set focus on the selectlist
}
// Adds a selected item into the picklist
function addIt() {
var selectList = document.getElementById("SelectList");
var selectIndex = selectList.selectedIndex;
var selectOptions = selectList.options;
var pickList = document.getElementById("PickList");
var pickOptions = pickList.options;
var pickOLength = pickOptions.length;
// An item must be selected
if (selectIndex > -1) {
pickOptions[pickOLength] = new Option(selectList[selectIndex].text);
pickOptions[pickOLength].value = selectList[selectIndex].value;
// If single selection, remove the item from the select list
if (singleSelect) {
selectOptions[selectIndex] = null;
}
if (sortPick) {
var tempText;
var tempValue;
// Sort the pick list
while (pickOLength > 0 && pickOptions[pickOLength].value < pickOptions[pickOLength-1].value) {
tempText = pickOptions[pickOLength-1].text;
tempValue = pickOptions[pickOLength-1].value;
pickOptions[pickOLength-1].text = pickOptions[pickOLength].text;
pickOptions[pickOLength-1].value = pickOptions[pickOLength].value;
pickOptions[pickOLength].text = tempText;
pickOptions[pickOLength].value = tempValue;
pickOLength = pickOLength - 1;
}
}
}
}
// Deletes an item from the picklist
function delIt() {
var selectList = document.getElementById("SelectList");
var selectOptions = selectList.options;
var selectOLength = selectOptions.length;
var pickList = document.getElementById("PickList");
var pickIndex = pickList.selectedIndex;
var pickOptions = pickList.options;
if (pickIndex > -1) {
// If single selection, replace the item in the select list
if (singleSelect) {
selectOptions[selectOLength] = new Option(pickList[pickIndex].text);
selectOptions[selectOLength].value = pickList[pickIndex].value;
}
pickOptions[pickIndex] = null;
if (singleSelect && sortSelect) {
var tempText;
var tempValue;
// Re-sort the select list
while (selectOLength > 0 && selectOptions[selectOLength].value < selectOptions[selectOLength-1].value) {
tempText = selectOptions[selectOLength-1].text;
tempValue = selectOptions[selectOLength-1].value;
selectOptions[selectOLength-1].text = selectOptions[selectOLength].text;
selectOptions[selectOLength-1].value = selectOptions[selectOLength].value;
selectOptions[selectOLength].text = tempText;
selectOptions[selectOLength].value = tempValue;
selectOLength = selectOLength - 1;
}
}
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++;
}
}
if (strValues.length == 0) {
alert("No has hecho ninguna selección");
}
else {
alert("Aquí están los valores seleccionados:\r\n" + strValues);
}
}
-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Kathi O'Shea (Kathi.O'[email protected]) -->
<!-- Web Site: http://www.web-savant.com/users/kathi/asp -->
<!-- Begin
function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if ( selectedText=="Svenska A"){
var xy="svenska A"
alert (xy);
<?php
$xy="Svenska A";
?>
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++
}
}
if (strValues.length == 0) {
alert("No has hecho ninguna selección");
}
else {
alert("Aquí están los valores seleccionados:\r\n" + strValues);
}
}
// End -->
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(gris.png);
}
.style2 {color: #FFFFFF}
-->
</style></head>
<body>
<table width="755" border="8" align="center" bordercolor="#FD802C" bgcolor="#FD802C">
<tr>
<td bgcolor="#FFFFFF"><p align="right"><span class="title"><span class="style2">.</span></span><span class="style2">....</span></p>
<p align="center" class="title">REGISTRERA</p>
<form name="choiceForm" method="post" action="prueva.php">
<p> </p>
<p> </p>
<table border=0 width="414">
<tr>
<td valign="top" width=180> <br>
<select name="available" size=10 onchange="moveOver();">
<option value= "Svenska A">Svenska A
<option value= "Svenska B">Svenska B
<option value=3>Actualizaciones de productos
<option value=4>Especificaciones de productos
<option value=5>Historia de pedidos
<option value=6>Estado del pedido
<option value=7>Contactos
<option value=8>Calendario de eventos
<option value=9>Planificación
<option value=10>Notas
</select></td>
<td valign="top" width=43><p> </p>
<p> </p>
<p>
<input name="button2" type="button" style="font-size: 8pt" onClick="removeMe();" value="Eliminar">
</p></td>
<td valign="top" width="151"><font size="2">:</font><br>
<select multiple name="choiceBox" style="width:150;" size="10">
</select></td>
</tr>
<tr>
<td colspan=3 height=10>
<input name="button2" type="button" style="font-size: 8pt" onclick="saveMe();" value="Obtener valores seleccionados"></td>
</tr>
</table>
<p> </p>
<p> </p>
<p><!-- This form is inoperational! Provisional users can't create forms NAME="theform" ID="theform" onSubmit="return false" -->
</p>
<input name="Submit" type="submit" value="Spara">
</form>
</table>
</body>
</html>
Valora esta pregunta


0