Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/12/2009, 18:14
Avatar de Killerx_8937
Killerx_8937
 
Fecha de Ingreso: noviembre-2006
Mensajes: 99
Antigüedad: 18 años, 3 meses
Puntos: 0
Pregunta llenar Select Con Otro Select

Hola Gente.

necesito de su voluntad para resolver mi problema, tengo que llenar un Select multiple llamado (EquipDesp) con los valores de 4 select, ( Mandante, Obras, Areas, Equipos) el problema no radica ahí sino en verificar que se selecciones los 4 select para agregar un nuevo valor a la lista y validar que no se ingresen duplicados en la misma.

ahora un poco de codigo

El Formulario

Código PHP:
<table border="1">
  <
tbody>
    <
tr>
      <
td>Mandantes</td>
      <
td>
        <
SELECT name="Mandantes">
        <
OPTION selected="0">seleccione</OPTION>
        <
OPTION value="ryv">ryv</OPTION>
        </
SELECT>
      </
td>
      <
td rowspan="2">
    <
INPUT type="button" name=">>" value=">>" class="button" onclick="verificaIns(this.form)">
      </
td>

      <
td rowspan="4">
        <
SELECT  id="EquipDesp" name="EquipDesp[]" multiple size="22" class="textbox" style="width:400px">
        </
SELECT>
    </
td>
    </
tr>
    <
tr>
      <
td>Obras</td>
      <
td>
        <
SELECT name="Obras" multiple="true">
        <
OPTION selected="0">seleccione</OPTION>
        <
OPTION value="cerro">cerro</OPTION>
              </
SELECT>
 
</
td>
    </
tr>
    <
tr>
      <
td>Areas</td>
      <
td>
        <
SELECT name="Areas">
        <
OPTION selected="0">seleccione</OPTION>
        <
OPTION value="Suelos">Suelos</OPTION>
        <
OPTION value="Hormigon">Hormigon</OPTION>
              </
SELECT>
</
td>
      <
td rowspan="2">
    <
INPUT type="button" name="<<" value="<<" class="button">
      </
td>
    </
tr>
    <
tr>
      <
td>Equipos</td>
      <
td>
        <
SELECT name="Equipos" multiple="true">
        <
OPTION selected="0">seleccione</OPTION>
        <
OPTION value="S01">Balanza</OPTION>
        <
OPTION value="S02">Varilla</OPTION>
        <
OPTION value="S03">Prensa</OPTION>
        <
OPTION value="S04">Molde</OPTION>
              </
SELECT>
</
td>
    </
tr>

  </
tbody>
</
table
y la funcion Javascript

Código PHP:
<script>
Function 
verificaIns(this.form){
// Obtengo las variables
Mandantesdocument.getElementById("Mandantes");
Areasdocument.getElementById("Areas");
Obrasdocument.getElementById("Obras");
Equiposdocument.getElementById("Equipos");
EquipDesp document.getElementById("EquipDesp");
// Hago las validaciones
if ((Mandantes.value == "0") || (Mandantes.value == null)) {
alert("Por favor selecciona un Mandante");
Mandantes.focus();
return 
false;
}
else
if ((
Obras.value == "0") || (Obras.value== null)) {
alert("Por favor selecciona una Obra");
Obras.focus();
return 
false;
}
else
if ((
Areas.value == "0") || (Areas.value== null)) {
alert("Por favor selecciona una Area");
Areas.focus();
return 
false;
}
else
if ((
Equipos.value == "0") || (Equipos.value== null)) {
alert("Por favor selecciona un Equipo");
Equipos.focus();
return 
false;
}
// busco en la lista si existe un valor igual 
for (i=0opti EquipDesp.options[i]; i++){
if (
opti.value == Mandantes.value+"|"+Obras.value+"|".Equipos.value)
{
alert('Ya existe en lista');
}
}
//esta es la parte que ingresa la nueva opcion
opt = new Option(Mandantes.value+"|"+Obras.value+"|"+Equipos.value,Mandantes.value+"|"+Obras.value+"|"+Equipos.value);
EquipDesp.options[EquipDesp.options.length] = opt;
}
</script> 
las vaidaciones funcioan pero cuando presiono el boton para agregar los valores a la lista nueva lo ingresa solo una ves incluso cambiando algun valor no vuelve a ingresar nada.

ayuda Pleace