Heather McVay
Heather McVay

Reputation: 949

Submitting Javascript form values

I have a mobile quiz, that I load 10 form questions into hidden divs, and after each question is answered, I fade and hide the question and unhide the next question, after they go through the 10 questions, how do I get it to post the actual data to the script waiting on the server ...form method=post action=process_quiz.php.. I am not really sure where/how to add that final submit button (obviously in the last div) but to work with the Javascript code to post the form data.

$(document).ready(function() 
{ 


        $('.btnNext').click(function()
        {

                $(this).parents('.questionContainer').fadeOut(500, function()
                {
                    $(this).next().fadeIn(500);
                });

        }); 

            $('.btnPrev').click(function()
            {
                $(this).parents('.questionContainer').fadeOut(500, function()
                {
                    $(this).prev().fadeIn(500);
                });


            });     
}); 

Upvotes: 2

Views: 620

Answers (1)

grasingerm
grasingerm

Reputation: 1953

$("#mySubmit").click(function(){
    $("#myForm").submit();
});

As long as the form has the following attributes defined:

<form action="process_quiz.php" method="post">

The documentation for jQuery form .submit() function is located here: http://api.jquery.com/submit/

It doesn't really matter where the button is located, or if it is even a submit button with the code above. If it is an actual submit button located within the form DOM element then it will automatically submit the form on click without you needing to specify it.

Upvotes: 2

Related Questions