I have a small javascript program that basically asks a user 60 questions. Each question answer a or b, and right now it has it set up for an onclick, the variables associated with each answer increase one. The problem I have obviously, is if the person clicks on one, then changes the answer, both variables are increased. I want to change it to become an onsubmit type situation if that is possible. Is it? or what is the alternative?

btw. im new to javascript if you couldn't tell :cheesy:

-Tipsy-

Recommended Answers

All 2 Replies

you can in your javascript (which is triggered on onclick in your case) do a submit of the form by simply calling the submit() function on the form.

that would work, but it will cause the form to submit after each answer and depending on the users connectin, that could be very time consumeing.

Are you using any backend processing? If so, I would simply name all your form elements so that you know what question they relate to and then process the completed form once submitted.

Other than that, you could use some sort of string concantenation and then try to process the string by loading into an array (each time someone chnges thier mind, your string would contain a second or 3rd entry for that question, you only want the last answer for any given question, so you set the array with an equal number of elements and use the question number to know what element to set (rememebr arrays often start at 0 so you many need question number -1) then process your array....

hope that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.