Decir que tengo esta lista desplegable:jQuery eliminar opciones seleccione Basado en otra Seleccione seleccionado (Necesita soporte para todos los navegadores)
<select id="theOptions1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
lo quiero para que cuando el usuario selecciona 1, esto es lo que el usuario puede elegir para desplegable 2:
<select id="theOptions2">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
O si el usuario selecciona 2:
<select id="theOptions2">
<option value="a">a</option>
<option value="b">b</option>
</select>
O si el usuario sele cts 3:
<select id="theOptions2">
<option value="b">b</option>
<option value="c">c</option>
</select>
probé el código publicado aquí: jQuery disable SELECT options based on Radio selected (Need support for all browsers)
Pero no funciona para las selecciones.
Por favor ayuda! ¡Gracias!
ACTUALIZACIÓN: me gusta mucho la respuesta Paolo Bergantino tenía en: jQuery disable SELECT options based on Radio selected (Need support for all browsers)
¿Hay alguna forma de modificar esto para trabajar con selecciona en lugar de botones de radio?
jQuery.fn.filterOn = function(radio, values) {
return this.each(function() {
var select = this;
var options = [];
$(select).find('option').each(function() {
options.push({value: $(this).val(), text: $(this).text()});
});
$(select).data('options', options);
$(radio).click(function() {
var options = $(select).empty().data('options');
var haystack = values[$(this).attr('id')];
$.each(options, function(i) {
var option = options[i];
if($.inArray(option.value, haystack) !== -1) {
$(select).append(
$('<option>').text(option.text).val(option.value)
);
}
});
});
});
};
Lo intentaré ahora mismo. Me gusta cómo mantener la interfaz de usuario bonita – Oscar
Este ejemplo me salvó un día de trabajo. ¡Gracias! –