How to handle multiple forms on one page?

On one page, I have a list of questions with different types of answers. (texboxes, checkboxes, etc.) The page is dynamically generated. I have to store responses in a database. What's the best way to do this? multiple forms or something else? it would be great if i could send an ajax request after every response, but i dont know how to do that (how to detect that the user has entered a response and went to the next question)

I am using asp.net mvc from C #

+2


source to share


2 answers


You can only submit one form per HTTP request, so to make things simpler you should only use one form and provide each response field with a unique name that can then be used on the server to map it to the database.

I suggest not submitting an AJAX request after the applicant has "finished" the question. Many people want to answer all questions and then repeat the answers a second time.



Therefore, I also recommend using the "wizard" approach (or one question per page and you will get the next question after submitting the current answer).

+1


source


I agree with Aaron's answer that you don't want to save the answer using an AJAX request after each question. However, if you ever run into a situation where you need to trigger an AJAX request based on user editing data in a form field, you can accomplish this by listening for Javascript events such as "onChange" and "onBlur" and trigger an AJAX request from this event listener.



+1


source







All Articles