JavaScript - rescate valor radiobutton

 
Vista:
sin imagen de perfil

rescate valor radiobutton

Publicado por Victor (11 intervenciones) el 18/02/2016 13:18:21
Tengo 3 radio que al clickear una se habilita cierta opcion, el problema que solo me toma el valor del primer radio y cuando presiono cualquiera de los otros 2 no me toma el valor, le puse un alert para ver y justamente solo me toma el primer valor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<table>
	<tr align="center" class="letraChica" >
		<td>
			<input class="" value="1" type="radio" name="obras" id="obras" />
			<label for="obras">INSTALACI&Oacute;N DE FAENAS</label>
		</td>
		<td>
			<input class="" value="2" type="radio" name="obras" id="obras" />
			<label for="obras">INSTALACI&Oacute;N DE GRUA</label>
		</td>
		<td>
			<input class="" value="3" type="radio" name="obras" id="obras" />
			<label for="obras">EJECUCI&Oacute;N EXCAVACIONES, ENTIBACIONES Y SOCALZADO</label>
		</td>
	</tr>
</table>

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
$('#obras').on('click', function () {
	if ($('#obras').val()==1) {
		//('input:radio[name=edad]:checked').val()
		alert($('#obras').val());
		$("#faenas").attr('style', 'display: block;');
		$("#grua").attr('style', 'display: none;');
		$("#excavaciones").attr('style', 'display: none;');
	}else{
		$("#faenas").attr('style', 'display: none;');
	}
 
 
	if ($('#obras').val()==2) {
		alert($('#obras').val());
		$("#faenas").attr('style', 'display: none;');
		$("#grua").attr('style', 'display: block;');
		$("#excavaciones").attr('style', 'display: none;');
	}else{
		$("#grua").attr('style', 'display: none;');
	}
 
 
	if ($('#obras').val()==3) {
		alert($('#obras').val());
		$(this).val()
		$("#faenas").attr('style', 'display: none;');
		$("#grua").attr('style', 'display: none;');
		$("#excavaciones").attr('style', 'display: block;');
	}else{
		$("#excavaciones").attr('style', 'display: none;');
	}
});
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

rescate valor radiobutton

Publicado por arck (74 intervenciones) el 23/02/2016 12:40:13
html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<table>
	<tr align="center" class="letraChica" >
		<td>
			<input value="1" type="radio" name="obras" id="obras" />
			<label for="obras">INSTALACI&Oacute;N DE FAENAS</label>
		</td>
		<td>
			<input value="2" type="radio" name="obras" id="obras1" />
			<label for="obras">INSTALACI&Oacute;N DE GRUA</label>
		</td>
		<td>
			<input value="3" type="radio" name="obras" id="obras2" />
			<label for="obras">EJECUCI&Oacute;N EXCAVACIONES, ENTIBACIONES Y SOCALZADO</label>
		</td>
	</tr>
</table>

Javascript

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
$('input:radio[name=obras]').on('click', function () {
	alert("prueba");
	if ($("input:radio[name=obras]:checked").val()==1) {
		alert($("input:radio[name=obras]:checked").val());
		$("#faenas").attr('style', 'display: block;');
		$("#grua").attr('style', 'display: none;');
		$("#excavaciones").attr('style', 'display: none;');
	}else{
		$("#faenas").attr('style', 'display: none;');
	}
 
 
	if ($("input:radio[name=obras]:checked").val()==2) {
		alert($("input:radio[name=obras]:checked").val());
		$("#faenas").attr('style', 'display: none;');
		$("#grua").attr('style', 'display: block;');
		$("#excavaciones").attr('style', 'display: none;');
	}else{
		$("#grua").attr('style', 'display: none;');
	}
 
 
	if ($("input:radio[name=obras]:checked").val()==3) {
		alert($("input:radio[name=obras]:checked").val());
		$(this).val()
		$("#faenas").attr('style', 'display: none;');
		$("#grua").attr('style', 'display: none;');
		$("#excavaciones").attr('style', 'display: block;');
	}else{
		$("#excavaciones").attr('style', 'display: none;');
	}
});
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