Donde esta el error en este script???
Publicado por Eduardo (1 intervención) el 12/05/2007 23:11:23
Necesito urgentemente saber donde esta el error en este script, se trata simplemente de una tabla donde se debe cambiar el color de la celda dependiendo de la respuesta dada por el usuario. El valor de la respuesta correcta se almacena en un campo hidden (V1). Si es correcta pone la celda en Verde, si es incorrecta pone en Verde la que es correcta y la que el usuario marco en Rojo. Creo que el codigo tiene el sentido correcto y deberia cumplir la funcion, pero al comprobarlo no hace nada. Tengo que terminarlo para entregarlo el Lunes y no funciona. Hecharme un cable plis. Saludos a todos/as.
<html>
<head>
<title></title>
<script>
function corregir()
{
if(p1resp == V1)
{
if(V1 == "A")
{
p1ca.style.backgroundColor="#669900";
}
if(V1 == "B")
{
p1cb.style.backgroundColor="#669900";
}
if(V1 == "C")
{
p1cc.style.backgroundColor="#669900";
}
}
if(!(p1resp == V1))
{
if(p1resp == "A")
{
p1ca.style.backgroundColor="#ff0000";
}
if(p1resp == "B")
{
p1cb.style.backgroundColor="#ff0000";
}
if(p1resp == "C")
{
p1cc.style.backgroundColor="#ff0000";
}
if(V1 == "A")
{
p1ca.style.backgroundColor="#669900";
}
if(V1 == "B")
{
p1cb.style.backgroundColor="#669900";
}
if(V1 == "C")
{
p1cc.style.backgroundColor="#669900";
}
}
}
</script>
</head>
<body>
<form name="test">
<table width="300px" border="1" style="border-collapse:collapse">
<tr>
<td id="p1ca"><input type="radio" name="p1resp" value="A">A) Celda 1</td>
</tr>
<tr>
<td id="p1cb"><input type="radio" name="p1resp" value="B">B) Celda 2</td>
</tr>
<tr>
<td id="p1cc"><input type="radio" name="p1resp" value="C">C) Celda 3</td>
</tr>
</table>
<input type="button" value="CAMBIAR" onclick="corregir()">
<input type="hidden" name="V1" value="A"><input type="hidden" name="V2" value="B"><input type="hidden" name="V3" value="C">
</form>
</body>
</html>
<html>
<head>
<title></title>
<script>
function corregir()
{
if(p1resp == V1)
{
if(V1 == "A")
{
p1ca.style.backgroundColor="#669900";
}
if(V1 == "B")
{
p1cb.style.backgroundColor="#669900";
}
if(V1 == "C")
{
p1cc.style.backgroundColor="#669900";
}
}
if(!(p1resp == V1))
{
if(p1resp == "A")
{
p1ca.style.backgroundColor="#ff0000";
}
if(p1resp == "B")
{
p1cb.style.backgroundColor="#ff0000";
}
if(p1resp == "C")
{
p1cc.style.backgroundColor="#ff0000";
}
if(V1 == "A")
{
p1ca.style.backgroundColor="#669900";
}
if(V1 == "B")
{
p1cb.style.backgroundColor="#669900";
}
if(V1 == "C")
{
p1cc.style.backgroundColor="#669900";
}
}
}
</script>
</head>
<body>
<form name="test">
<table width="300px" border="1" style="border-collapse:collapse">
<tr>
<td id="p1ca"><input type="radio" name="p1resp" value="A">A) Celda 1</td>
</tr>
<tr>
<td id="p1cb"><input type="radio" name="p1resp" value="B">B) Celda 2</td>
</tr>
<tr>
<td id="p1cc"><input type="radio" name="p1resp" value="C">C) Celda 3</td>
</tr>
</table>
<input type="button" value="CAMBIAR" onclick="corregir()">
<input type="hidden" name="V1" value="A"><input type="hidden" name="V2" value="B"><input type="hidden" name="V3" value="C">
</form>
</body>
</html>
Valora esta pregunta


0