<html>
<head>
<title>Selecciona elementos en la lista</title>
</head>
<BODY style="font-family: Verdana">
<p align="center"><b>Selecciona elementos en lista 2</b></p>
<SCRIPT LANGUAGE="JavaScript">
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 (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 {
onSubmit();
}
}
// End -->
</script>
</HEAD>
<html>
<head>
<title>Selección de elementos</title>
</head>
<BODY style="font-family: Verdana">
<center>
<form name="choiceForm" method="post" action="lista.php">
<table border=0 width="414">
<tr>
<td valign="top" width=227>
<font size="2">Contenido disponible: </font>
<br>
<select name="available" size=10 onchange="moveOver();">
<option value="funcionarios">Funcionarios
<option value="cargo_trabajador">Cargo Trabajador
<option value="actualizar">Actualizaciones de productos
<option value="especificacion">Especificaciones de productos
<option value="historia">Historia de pedidos
<option value="estado_pedido">Estado del pedido
<option value="contactos">Contactos
<option value="calendario">Calendario de eventos
<option value="planificaciones">Planificación
<option value="notas">Notas
</select>
</td>
<td width="177" valign="top" bordercolor="#CCCCFF"> <font size="2">Tu
selección: </font> <br>
<select multiple name="choiceBox[]" id="choiceBox" style="width:150;" size="10">
</select>
</td>
</tr>
<tr>
<td height=10 width="390">
<input type="button" value="Eliminar seleccionados" onclick="removeMe();" style="font-size: 8pt"><br>
<input type="submit" value="Obtener valores seleccionados" onclick="saveMe();" style="font-size: 8pt"><br>
<input type="button" value="Seleccionar todos" onclick="selAll(true)" style="font-size: 8pt"><br>
<input type="button" value="Quitar selección" onclick="selAll(false)" style="font-size: 8pt"><br>
</td>
</tr>
</table>
</form>
</center>
<script>
function selAll(_v) {
for(var i=0;i<document.choiceForm.choiceBox.length;i++)
document.choiceForm.choiceBox[i].selected=_v;
}
</script>
</body>
</html>