Slacker616
Slacker616

Reputation: 855

Creating javascript for dynamic controls?

I want to create a javascript code for validating dynamic controls i have created from a database using php and html. in the database i have a table with questions and answers, the questions and the options (answers) are created dynamically. But i want to validate these controls with javascript, let's say i have 100 questions, i don't want to create 100 different validations for each questions, even worse if more questions are added to the database they will be added to the page, but i wont't have a way to validate the new answers. How could i create the javascript dinamically as well as the questions and answers? I hope all that makes a little sense.

Upvotes: 0

Views: 310

Answers (1)

iDaemon
iDaemon

Reputation: 363

Try implementing following steps.

  1. You can create a javascript function which will receive question and answer as parameters.
  2. Create hidden input type and when you want to validate (for e.g. on submit event) assign values to hidden elements and call the function.
  3. In javascript function use AJAX code and use you server side script(e.g.PHP,ASP,CGI) to actually validate your question and answer.
  4. Server side script will return the response and then you can handle it on your html page.

Upvotes: 1

Related Questions