I have been working with html and javascript for a couple of days and I'm stuck at this point. I need to take an answer for an mcq and display whether it is right or wrong Why is the if condition not entered ?
I have just put a simple javascript using GetElemntById and .checked with .value this is not a school assignment this is some thing that i have been planning for a long time
<html>
<head>
<script>
document.write("In javascript");
function myFunction()
{
document.write("In the function");
if(document.getElementById('a1').checked)
{
document.write("in if");
var x = document.getElementById('a1').value
document.write(x);
}else
{
document.write("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
}
</script>
</head>
<body>
<p> How much is 2+2 ?? </p>
4 : <input type="radio" name="ans" id="a1" value="4"><br/ >
5 : <input type="radio" name="ans" id="a2" value="5"><br/ >
6 : <input type="radio" name="ans" id="a3" value="6"><br/ >
7 : <input type="radio" name="ans" id="a4" value="7"><br/ >
<button onClick="myFunction()">clickz</button>
</body>
</html>