Dave, I just want to add numbers together, get an answer, and retrieve a document represented by the answer. I have 11 pages for people to answer “yes” or “no” on. I have my “yes” and “no” buttons working properly. What I need to do is assign numerical values to each button on each page. Then I need to add the values of all 11 pages of each button pushed to get one answer. I want to use this answer to retrieve one document to be displayed for the viewer. Maybe you know of some tricks that can be used in HTML to do this. I was thinking if I can’t do it in HTML, maybe javascript might be an answer.
You pose an interesting question. The easiest way to solve this, I think, is to produce a small CGI script that modifies each of the 11 pages as sent so that they’re actually all forms. Then the answers to each question are simply the sum value to that point in the 11 questions plus the point value for that particular answer to the question.
This type of approach could be used to ascertain a Myers-Briggs personality profile, for example, where a set of questions would be used to determine which of each possible alternative pair applies best to the visitor (e.g., “introvert”, or “extrovert”, etc).
For example, if your fourth question is “Swallows are the fastest bird” and the two possible answers are “yes” (worth 2 points) and “no” (worth 1 point), and the person is going into this question with a sum value of 7 points, it could be structured thusly:
Swallows are the fastest bird<br /> <input type="radio" name="ans4" value="9"> yes <br /> <input type="radio" name="ans4" value="8"> no <br />
See what I’m getting at here? Your CGI script would look for values to ans1, ans2, ans3, etc., through 11, to figure out what page the visitor’s on, then look at the value of that variable to ascertain the sum score to that point.
When the CGI script sees “ans11” then the value of “ans11” is actually the final sum value of the survey and you could easily have solution pages that are simply named after their numeric value, as in 1.html, 2.html and so on.
You could also do this in a number of different sophisticated ways, including using JavaScript to step through all the questions without ever leaving the Web page and touching your server. This has the advantage of being much more efficient in terms of server use, but it’ll be considerably harder to program and, possibly, modify to fix typos, re-weight questions, etc.
Yet another approach would be to use a sophisticated combination of JavaScript and Cascading Style Sheets, where all the questions would be loaded at once, but only the current question would have its “visibility” set to true. Again, more efficient in terms of your server load, but more difficult to program correctly.
I hope this gets you traveling in the right direction. Good luck!
How do I sum up answers on an HTML Web-based form?
Dave, I just want to add numbers together, get an answer, and retrieve a document represented by the answer. I have 11 pages for people to answer “yes” or “no” on. I have my “yes” and “no” buttons working properly….