Foros del Web » Programando para Internet » Javascript »

agregar option a select

Estas en el tema de agregar option a select en el foro de Javascript en Foros del Web. Hola tengo el siguiente troso de codigo q lo unico q hace es agregar opciones a un select: sortitems = 1; function move(fbox,tbox) { for(var ...
  #1 (permalink)  
Antiguo 12/01/2007, 10:02
 
Fecha de Ingreso: junio-2004
Mensajes: 170
Antigüedad: 19 años, 10 meses
Puntos: 0
Exclamación agregar option a select

Hola tengo el siguiente troso de codigo q lo unico q hace es agregar opciones a un select:

sortitems = 1;

function move(fbox,tbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options[i].selected && fbox.options[i].value != "") {
var no = new Option();
no.value = fbox.options[i].value;
no.text = fbox.options[i].text;
tbox.options[tbox.options.length] = no;

fbox.options[i].value = "";
fbox.options[i].text = "";
}
}
BumpUp(fbox);
if (sortitems) SortD(tbox);
}
function BumpUp(box) {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].value == "") {
for(var j=i; j<box.options.length-1; j++) {
box.options[j].value = box.options[j+1].value;
box.options[j].text = box.options[j+1].text;
}
var ln = i;
break;
}
}
if(ln < box.options.length) {
box.options.length -= 1;
BumpUp(box);
}
}

function SortD(box) {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++) {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++) {
for(var y=(x+1); y<temp_opts.length; y++) {
if(temp_opts[x].text > temp_opts[y].text) {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
}
}
}
for(var i=0; i<box.options.length; i++) {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
}
}


En los botones, con los cuales mando los datos tengo:

boton para enviar:
onClik(javascript:move(select1,select2))

boton para recibir:

onClik(javascript:move(select2,select1))

El problema es que cuando quiero ver si realmente el select 2 tiene algún dato colocando:

document.write(tbox.options[i]).value);

no me muestra nada, oesta malo?

saludos
  #2 (permalink)  
Antiguo 12/01/2007, 14:51
 
Fecha de Ingreso: abril-2002
Mensajes: 1.014
Antigüedad: 22 años
Puntos: 8
Re: agregar option a select

No has puesto un paréntesis de más?

Código:
document.write(tbox.options[i]).value);
También tienes por ahí onClik y es onClick (dan igual mayúsculas y minúsculas)
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:37.