combos dependientes - ie se cierra
Publicado por list (1 intervención) el 04/12/2008 20:31:55
Hola estoy manejando 2 combos, intento q si selecciono una opción determina de la primera se borren opciones de la segundo, y q cd pulse de nuevo la opcion se inserten, el problema es que si lo quiero es que se elimine una opción no hay problema pero si intento eliminar 2 opciones de la segunda combo, en firefox funciona pero ie se cierra aqui dejo el codigo, aver si me pueden exar una mano.
ESTE CÓDIGO ES PARA ELIMINAR 1 OPCION AL LIMINAR 2 NO FUNCIONA
<form name="formulario" id="formulario" action="#" >
<select name="combo1" id="combo1" class="texto" onchange="cambiar(this)" >
<option value="1"> combo1opcion1
<option value="2"> combo1opcion2
<option value="3"> combo1opcion3
</select>
<select name="combo2" id="combo2" class="texto">
<option value="1"> combo2opcion1
<option value="2"> combo2opcion2
<option value="3"> combo2opcion3
</select>
</form>
window.onload = init;
function init()
{
var indice = document.formulario.combo1.selectedIndex;
var valor = document.formulario.combo1.options[document.formulario.combo1.selectedIndex].value;
if(valor!=1)
{
removeOption();
}
}
comprobarDestinoFormadePago=function(combo)
{
var indice = combo.selectedIndex;
var valor = combo.options[combo.selectedIndex].value;
if(combo.id=='destino')
{
if(valor!=1)
{
removeOption();
}
else
{
insertOption();
}
}
}
function insertOption()
{
var oOption=document.createElement('option');
oOption.text='combo2opcion1';
oOption.value=3;
var x=document.getElementById("combo2");
try
{
x.add(oOption,3); // standards compliant
}
catch(ex)
{
x.add(oOption); // IE only
}
}
function removeOption()
{
var x=document.getElementById("combo2")
x.remove(2)
}
var indice = document.formulario.combo1.selectedIndex;
var valor = document.formulario.combo1.options[document.formulario.combo1.selectedIndex].value;
if(valor!=1)
{
removeOption();
}
ESTE CÓDIGO ES PARA ELIMINAR 1 OPCION AL LIMINAR 2 NO FUNCIONA
<form name="formulario" id="formulario" action="#" >
<select name="combo1" id="combo1" class="texto" onchange="cambiar(this)" >
<option value="1"> combo1opcion1
<option value="2"> combo1opcion2
<option value="3"> combo1opcion3
</select>
<select name="combo2" id="combo2" class="texto">
<option value="1"> combo2opcion1
<option value="2"> combo2opcion2
<option value="3"> combo2opcion3
</select>
</form>
window.onload = init;
function init()
{
var indice = document.formulario.combo1.selectedIndex;
var valor = document.formulario.combo1.options[document.formulario.combo1.selectedIndex].value;
if(valor!=1)
{
removeOption();
}
}
comprobarDestinoFormadePago=function(combo)
{
var indice = combo.selectedIndex;
var valor = combo.options[combo.selectedIndex].value;
if(combo.id=='destino')
{
if(valor!=1)
{
removeOption();
}
else
{
insertOption();
}
}
}
function insertOption()
{
var oOption=document.createElement('option');
oOption.text='combo2opcion1';
oOption.value=3;
var x=document.getElementById("combo2");
try
{
x.add(oOption,3); // standards compliant
}
catch(ex)
{
x.add(oOption); // IE only
}
}
function removeOption()
{
var x=document.getElementById("combo2")
x.remove(2)
}
var indice = document.formulario.combo1.selectedIndex;
var valor = document.formulario.combo1.options[document.formulario.combo1.selectedIndex].value;
if(valor!=1)
{
removeOption();
}
Valora esta pregunta


0