1. Tech

Your suggestion is on its way!

An email with a link to:

http://javascript.about.com/library/blquizf.htm

was emailed to:

Thanks for sharing About.com with others!

Analysis Quiz

1. Quiz Head Script

This quiz has no right and wrong answers. Instead each answer has a numeric value assigned to it and the values for the selected answers are added up to give a final total which is then converted into a percentage figure where zero percent means that the lowest valued answer was selected every time and 100 percent means that the highest valued answer was selected each time. If intermediate valued answers are selected or a mix of high and low valued answers is selected then an intermediate percentage value will result.

To create the script you must first enter the questions and answers for your quiz into the form below (if the advertising scripts on this page stop the form from working then use this copy of the form). You also need to assign values between 0 and 9 to each answer. Once you have entered a question and four alternative answers then select the "Add Question" button.

Continue adding as many questions and answers as you require. You can add as many as you like but if you add too many then your quiz page may take a long time to load.

The script will display the questions you enter one at a time. When an answer is selected and the "Next Question" button pressed the value associated with the selected answer will be added to the current total and will be encrypted and passed to the next question.

At the end of the quiz the total of all of the selected answers will be converted into a percentage and passed to the analysis page that you specify.

The script code for the quiz will appear in the text box below with an additional statement being added for each question you add. Don't worry if you make a mistake as you can always delete lines from the resulting code if you want to remove questions. If you decide you want to start over, simply refresh the current page.

Note that the analysis page will need to have Javascript added to it to perform the analysis so if your web hosting setup requires a particular naming convention for pages using Javascript then you will need to keep this in mind when specifying the analysis page name here.

Question:
Answer One
Answer Two
Answer Three
Answer Four
This entry contains HTML code.
Analysis Page:

Once you have finished entering your questions and answers, copy the code from the above text box and save it as a file called quizhead.js. You can rearrange the lines if you want to change the order of the questions or delete lines to remove questions you decide not to include. The only limitations are that you cannot change the first line of the code and you must have at least one question for the quiz script to work.

You now add this quiz to the head section of the page where the quiz is to appear using the following code:

<script src="quizhead.js"
type="text/javascript">
</script>

If you are creating more than one quiz then you can use different names for the files where you save the quizes as long as they end in .js and that you modify the code going into the head of the individual quiz pages to reference the appropriate quiz files you have created.

So now that we have created the questions and answers the next step is to obtain the body script that will display them on your page.

©2017 About.com. All rights reserved.