I want to create a script that does the following:
When answering questions via a radio, drop-down, or checkbox, the script checks
When selecting a radio button (or dropdown, or any form element except text and textarea) it checks if the given option will make the script to ask more questions.
Example:
A checkbox in front of ‘Call me back’, which when checked shows 2 more fields (a dropdown with all available countries, and a textfield for their phonenumber)
Another example:
(Let’s say we’re end-user IT support)
A dropdown menu where the user can select on what topic they want support (i.e. hardware, software). Then when the user selects a topic, it will show a additional field with more topics (ex: when user selects hardware, they get phone, computer, etc.), which on their turn shows extra fields for serial number, maybe OS’es and so forth
I think I’ll be able to figure out how to do it in PHP and SQL, I just need a bit of a push in the right direction with HTML and jQuery:AJAX
I hope I’m clear enough in what I want the script to do..
Thanks in advance! 🙂
Assuming some html structure like this:
And using jQuery library (which makes life lots easier in cases like this) you can do this:
As demonstrated here: http://jsfiddle.net/xtUk6/
Ajax is not necessary here. The concept is that you have all the form fields there on the page, just visually removed. Then, each question has it’s own unique id that can be identified when the form is posted back to the server and handled there in your case by php.
Using Ajax is possible, but unless you have millions of questions to select from according to some very complex set of input scenarios, it would cause delay whilst it is constantly fetching the next question from the server.