Código:
function addlista(texto1,texto2,form){
if(texto1=="" && texto2==""){
alert('Por favor, tiene que ingresar el nombre\ny el domicilio para cargar la lista');
}else{
if(texto2==""){
valor=texto1
}else{
valor=texto1+" - "+texto2
}
value='<object value="'+valor+'">'+valor+'</option>'
if(buscarEnLista(valor,form)){
var newOption = new Option(valor,value)
form.options[form.options.length] = newOption
}else{
alert('el elemento ya esta en la lista...')
}
}
}
Código:
as funciones hacen esto:function buscarEnLista(texto,form){
i=0
b=true
while(i < form.options.length && b){
if(texto==form.option[i].text){
b=false
}else{
i=i+1
}
}
return b
}
Tengo dos campos de texto en HTML y un campo SELECT. Cuando escribo algo en los campos de texto y hago click en un boton quiero que el texto de los formularios se ingrese al SEECT.
La funcion addlista funciona correctamente si saco esto:
Código:
y lo dejo como if(buscarEnLista(valor,form)){
var newOption = new Option(valor,value)
form.options[form.options.length] = newOption
}else{
alert('el elemento ya esta en la lista...')
}
Código:
pero cuando pongo el IF, funciona solo una vez, y cuando intento agregar un segundo elemento, me marca un error.var newOption = new Option(valor,value) form.options[form.options.length] = newOption
¿ustedes podrian ayudarme al respecto?
Desde ya muchas gracias.

