JQuery - activar select o combobox con otro

 
Vista:
Imágen de perfil de bit

activar select o combobox con otro

Publicado por bit (2 intervenciones) el 07/02/2014 09:26:26
ESTO FUNCIONA MUY BIEN CON JAVASCRIPT PERO CON JQUERY?:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta title="habilitar, deshabilitar combos según selección en otro combo">
 
	<script>
		function habilitar(value)
		{
			if(value=="1" || value==true)
			{
				// habilitamos
				document.getElementById("segundo").disabled=false;
			}else if(value=="2" || value==false){
				// deshabilitamos
				document.getElementById("segundo").disabled=true;
			}
		}
	</script>
</head>
 
<body>
<form>
	<h1>habilitar, deshabilitar combos según selección en otro combo</h1>
	<div>
		<select name="primero" id="primero" onchange="habilitar(this.value);">
			<option value='0'>selecciona</option>
			<option value='1'>habilitar el segundo</option>
			<option value='2'>deshabilitar el segundo</option>
		</select>
	</div>
	<div>
		<select name="segundo" id="segundo">
			<option value='1'>seleccion 1</option>
			<option value='2'>seleccion 2</option>
		</select>
	</div>
</form>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

activar select o combobox con otro

Publicado por bathorz (2 intervenciones) el 07/02/2014 10:01:15
Mas o menos lo mismo.
1
2
3
4
5
6
7
8
9
10
11
$(document).ready(function() {
            $("#primero").on("change", function() {
               var valor = $("#primero").val();
               if (valor === "1" || valor === true) {
                  $("#segundo").attr('disabled', false);
               } else if (valor === "2" || valor === false) {
                  // deshabilitamos
                  $("#segundo").attr('disabled', true);
               }
            });
         });
Elimina: onchange="habilitar(this.value);"
<select name="primero" id="primero" >
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de bit

activar select o combobox con otro

Publicado por bit (2 intervenciones) el 08/02/2014 10:50:17
EXCELENTE..!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar