First, thanks in advance for any helpful replies. Second, I am just starting to learn javascript, so please excuse any awkwardness in the code writing. My overall objective is to create a quiz, that when the user clicked the answer button, the background color of each answer will indicate if it is correct (green) or wrong (red). However, I don't want anyone giving me the answer (how else will I learn), rather nudge me in the right direction in the hope I figure it out myself.
At this point, I am able to change the background color of a cell in a table
with a click of the button. However, I got stuck when I added an input
type="radio." It was not responding the way I hope it would.
Here is my code:
<table>
<tr>
<td><input id="yy" type="radio" value="T"></td>
<td id="pdd">True answer.</td>
<td></td>
</tr>
</table>
<button onclick="tst()">Show Answer</button>
<script>
function tst() {
var y = document.getElementById('pdd');
var z = document.getElementById('yy');
if (z.value = 'F') {
y.style.backgroundColor = 'red';
} else {
y.style.backgroundColor = 'yellow';
}
}
</script>
What I want to happen is the system looks at the input sees that the value='T'. It would suppose to turn the background to yellow. In the condition, I purposely made it 'F' to see if the system goes through it and reads (it does not.) Obviously I am missing something. I have a feeling that I am not hitting the input right. I looked around for discussions on input[value] and I saw some but there were not much explanation on it.