You want an event fired when the user clicks the submit button.

Look here: http://docs.jquery.com/Events/submit#fn

That example should get you going.

Now there are two scenarios for you to choose from:

(1) When the submit button is clicked, you want to call an ajax
method, passing all the form parameters, with the method GET or POST,
to a PHP page that determines which answers are correct, returning a
data structure that you can then parse.
Look here: http://docs.jquery.com/Ajax
There is a method for just using POST (jQuery.post()) but I would be
inclined to use the main jQuery.ajax() method - it gives you more
control, with timeout and error handling.
When the data is successfully returned, you parse the data structure
using jQuery.each().

(2) All the correct answers are in an object already on your page in
the header, something like:

var answers = {
    "q1":"2",
    "q2":"3",
    "q3":"1",
    "q4":"4"
}

Then this is just a question of using $.each() (http://docs.jquery.com/
Utilities/jQuery.each#objectcallback) to iterate over this 'answers'
object, comparing with what was sent when the submit button was
clicked.

When you have your result, create a <div> element with the score. See
the Manipulation section of the help: http://docs.jquery.com/Attributes/html
You can get fancy with fade in effects (http://docs.jquery.com/
Effects) if you like.

If you need to redirect to one of four pages, use replaceWith()
(http://docs.jquery.com/Manipulation/replaceWith#content) and
everything, although I don't think this is a particularly elegant
approach.

My preference would be to go for the AJAX solution, since you can use
the same PHP code you have already, but just pass an extra variable in
the query string, like returnStatus=True for a Javascript query and
returnStatus=False for a PHP query. Then in your PHP logic, if you see
returnStatus=True you return a PHP array to the initial form page, and
if not, you echo out the result as normal.

HTH

On Apr 15, 8:32 am, "poundcommapo...@gmail.com"
<poundcommapo...@gmail.com> wrote:
> Hi. I have what I feel like should be a simple problem, but I'm having
> a hard time sorting it out. The page is located 
> here:http://staging.pixelluxe.com/tbs/
> I apologize in advance that all the code is on one line - client
> request (also, the inline styles are their requirement).
>
> Anyway, this is a simple quiz. There are 8 multiple-choice questions
> in sets of radio groups. Each radio group has four possible answers
> with values of 1, 2, 3, or 4.
>
> On submit, I need a script to add up the user's selections and
> redirect the user to 1 of 4 pages depending on the total score. I'm
> currently doing it with a simple PHP script and meta-refresh, but the
> client wants a client-side solution, with the PHP only as a backup if
> JavaScript is disabled.
>
> Anyone know how to make that happen? Thanks so much.

Reply via email to