
i m creating a set of online questionnaire consist of 12 questions with choice of answers from 0-6.i've done creating a html codes.but have to calculate percentage based on total scores.my problem is i want to use get element by id function to read the score.if any questions is missed out there must be an alert box require user to answer all questions before proceeding to calculate score.below is a sample of questionnaire which i need to modify to include get element id function.I REALLY NEED YOUR HELP IN THIS.PLS
<form method="GET" action="post.html">`print("code sample");`
Choose one from this group<br>
RED <input type = "radio" name = "rad1" value = "0" >
BLUE <input type = "radio" name = "rad1" value = "1" >
GREEN <input type = "radio" name = "rad1" value = "2" >
YELLOW <input type = "radio" name = "rad1" value = "3">
BROWN <input type = "radio" name = "rad1" value = "4">
<br>
And one from this group<br>
PINK<input type = "radio" name = "rad2" value = "0" >
PURPLE<input type = "radio" name = "rad2" value = "1" >
GREY<input type = "radio" name = "rad2" value = "2" >
BLACK<input type = "radio" name = "rad2" value = "3" >
WHITE <input type = "radio" name = "rad2" value = "4">
<br><br>
<input type = "button" value = "Calculate Score" onclick ="calc()">
</form>
<script type = "text/javascript">
var numOfGroups = 2; // the number of radio button groups - here 2
function calc() {
var score = 0;
for (var j=1; j<=numOfGroups; j++) {
var f = document["myform"]["rad"+j];
for (var i=0; i<f.length; i++) {
if (f[i].checked) {
score += Number(f[i].value/72 *100));
}
}
}
alert ("You scored " + score);
}
</script>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.