Hello experts,
I am trying to create a simple questionnaire using frontpage with a total of 16 questions using Javascript and HTML. The questions are big and so they will be distributed in 4 pages. The first page will have 3 questions, the 2nd will have 5 questions, the 3rd will have 5 questions and the 4th page 4 questions. Each question will have a TRUE or FALSE answer, using radio buttons. I have already inserted the form, typed in the questions and layed out the radio buttons.
At the end of the questionnaire there will be a "Submit button", which should validate that all questions have been answered, if not, an Alert message should pop up. Since the questions are True or False, each questions will have a right answer, and at the end when the user presses the submit button, the function should be able to add up all the right answers and if the number of right answers are GREATER THAN 12, then a message should pop up saying "CONGRATULATIONS". If the number of right answers are LESS THAN 12, then a pop up should come up ALERTING THE QUESTIONS THAT NEED TO BE WORKED ON (indicating the chapters to be worked on)
I already started out coding in Javascript with just 3 questions, and this is what I have so far. I haven't taken any formal classes in javascript & html, so am just using some knowledge from books. Any help on this would be greatly appreciated.
<title>Page 1 of 4</title>
</head>
<body>
<form name="testpage1">
<p>Question 1: 1<input type="radio" name="R1" onClick="choice1=1">0<inpu
t
type="radio" name="R1" onClick="choice1=0" ></p>
<p>Question 2: 1<input type="radio" name="R2" onClick="choice2=1">0<inpu
t
type="radio" name="R2" onClick="choice2=0" ></p>
<p>Question 3: 1<input type="radio" name="R3" onClick="choice3=1">0<inpu
t
type="radio" name="R3" onClick="choice3=0" ></p>
<p><input language="javascript" type="button" value="Submit" name="sub"
onClick="validate(this.for
m)"></p>
</form>
</body>
<script language="Javascript1.1">
var final=0
var choice1=0
var choice2=0
var choice3=0
function validate(frm)
{
var c=0;
for(var i=0;i<frm.elements.length;
i++)
{
if(frm.elements[i].type == "radio" && frm.elements[i].checked)
{
c++;
}
}
if(c < 3)
{
alert(" Please answer all of the questions/n");
}
else
{
final = choice1 + choice2 + choice3;
alert (final);
}
}
Start Free Trial