0

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.

2
  • Could you give us some code as an example? Commented May 22, 2012 at 4:00
  • 1
    use arrays creatively to store the values of correct answers. Commented May 22, 2012 at 4:07

1 Answer 1

1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.