Click here to Skip to main content
15,917,455 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys.Can anyone please point me in the right direction?I'm trying to create a dynamic form in html with the following structure :
The user is trying to create a survey/quiz.So the form allows them to create all the questions they want for this survey.Next, each question can have as many answers as they wish.So this form needs to be highly dynamic.So the first step is, you type in your first question which will be the first on your survey,then below it appears only one input field for your answer.You can click a button,to add another input field for more answer options.Every question and all its answers are eventually supposed to be stored in a mysql db and will be linked using Primary key foreign key relationships.So far i only have input fields for the question and answer and can add another row of each using javascript.
My challenge is
-i do not know how to link the answers to their parent question
-i do not know to create an edit panel where users can view all the questions and their answers and possibly edit them.

Any pointers,advice,tutorials,sample code that will help me achieve this kind of structure will be highly appreciated.Thank you so much for your time.

1 solution


To link parent questions to answers: as you create a new Q/A block, you'll need to give them a name &/or ID (presuming you wish to save them somewhere). Create these with fixed prefixes so that the first pair is id='Q1' and id='A1'. When you generate the next, simply increment the numerical suffix.

To edit them: I would present the user a list of Q's/A's that they've entered. It would have a link generated for that specific pair and would open it in a new tab/window for editing that particular question.

If you're using a database, the link reference could be (should be) an unique identifier (identity column recommended). How you arrange your data linkage, especially with multiple users and multiple question sets . . . that I'll leave to you.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900