Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/07/2010, 07:48
matias_80
 
Fecha de Ingreso: noviembre-2006
Ubicación: Capital Federal
Mensajes: 141
Antigüedad: 17 años, 6 meses
Puntos: 1
Sonrisa Agregar y Quitar Elementos de un select

Hola amigos necesito de su ayuda.....estoy agregando mediante un campo de texto elementos a un select con el tipico boton de agregar y el boton de quitar.....

resulta q tengo 3 problemas....

1) en Internet explorer cuando agrego el elemento, en el select no me muestra el texto, si agrega el elemento pero no lo muestra....
2)Agrego elemento al select y si le doy f5 me limpia todo el select.....
3) deberia hacer una validacion ue si ingreso un numero q ya existe en el select me diga q ya esta.....

Les dejo mi codigo por si alguien me puede ayudar.......

<script>

function agregar(){

var numeroFactura = document.getElementById("numeroFactura");
var listaFacturas = document.getElementById("listaFacturas");

//valido el campo numeroFactura
if ( numeroFactura.value == "" ){
alert("Por favor, ingrese un valor");
numeroFactura.focus();
return false;
}
if( isNaN(numeroFactura.value) ) {
alert('Por favor, ingrese solo valores numéricos');
numeroFactura.focus();
return false;
}
if( !(/^\d{8}$/.test(numeroFactura.value)) ) {
alert('Por favor, ingrese los últimos 8 digitos de su factura');
numeroFactura.focus();
return false;
}

//paso las facturas al select
var option=document.createElement("option");
option = new Option(numeroFactura.value,numeroFactura.value);
listaFacturas.appendChild(option);

return true;
}

function quitar(){
var aQuitar = document.getElementById("listaFacturas");
aQuitar.options[aQuitar.selectedIndex] = null;
}


</script>


HTML
<input type="text" id="numeroFactura" value="" maxlength="8" size="10" name="numeroFactura"/>

<input type="button" onclick="agregar();" value="agregar" class="button" />

<input type="button" onclick="quitar();" value="quitar" class="button" />

<select multiple="multiple" class="wideSelect" id="listaFacturas" name="numeroFacturas">
</select>

MUCHAS GRACIAS!!