Ver Mensaje Individual
  #13 (permalink)  
Antiguo 08/12/2010, 08:32
Avatar de IsaBelM
IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 16 años, 8 meses
Puntos: 1012
Respuesta: Examen con imput radio

este mismo tema ha sido tratado hace poco y he tomando algo del código, para adaptarlo a que pretendes hacer
Cita:
<html>
<head>
<script type="text/javascript">
var corr = ['b', 'c'];
var niv = {0 : 'Bajo', 1 : 'Medio', 2 : 'Avanzado'}
function fnc() {
var aciertos = 0;
var radio_checked = -1;
for(var j = 0, rad = document.getElementsByTagName('input'); j < rad.length-1; j++){
if(rad[j].checked) {
radio_checked++;
if (rad[j].value == corr[radio_checked]) {
document.getElementById(rad[j].parentNode.id).style.backgroundColor = '#9BFFA0';
aciertos++;
} else {
document.getElementById(rad[j].parentNode.id).style.backgroundColor = '#FF8C8C';
}
}
}
document.getElementById('nivel').innerHTML = 'Nivel: ' + niv[aciertos];
}
</script>
</head>
<body>
<form>
<label for="p1" id="rad1">Pregunta 1
<input type="radio" value="a" name="p1" />a
<input type="radio" value="b" name="p1" />b
<input type="radio" value="c" name="p1" />c
</label>
<br />
<label for="p2" id="rad0">Pregunta 2
<input type="radio" value="a" name="p2" />a
<input type="radio" value="b" name="p2" />b
<input type="radio" value="c" name="p2" />c
</label>
<div id="nivel"></div>
<input type="button" onclick="fnc()" value="comprobar" />
</form>
</body>
</html>