jQuery - deshabilitar / habilitar opciones de selección
Necesito un poco de ayuda con jQuery si condición. ¡He estado buscando y haciendo pruebas durante horas, cualquier ayuda sería genial! Obtengo este código HTML:
<label id="label1" for="date_from">Value:</label>
<input value="" />
<select id="select1" name="select1">
<option>No Match</option>
<option value="1">Test</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
<select id="select2" name="select2">
<option>No Match</option>
<option value="1">Test</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>
y esta función jQuery:
if ( $('#label1').val() < 3 ) {
$('select').change(function() {
$('#select1, #select2').not(this)
.children('option[value=' + this.value + ']')
attr('disabled', true)
.siblings().removeAttr('disabled');
});
}
else {
$('select').change(function() {
$('#select1, #select2').not(this)
.children('option[value=' + this.value + ']')
.attr('disabled', false)
.siblings().removeAttr('disabled');
});
}
Soy un principiante en jquery, y no sé si este código está escrito correctamente porque no funciona.
El problema es:
Cuando el valor de entrada es menor que 3, la opción de selección en select2 es la misma que en select1 y el resto de opciones en select2 se deshabilitan. Cuando el valor de entrada es mayor que 3, se habilitan las opciones en select1 y select2.
Saludos cordiales, Gracias por leer este post de jquery newbie ...