View Full Version : Looking for web based decision tree script
01-05-2011, 04:52 PM
I would like to put a script on our website that users could interact with and that would ask a series of questions and based on those questions propose answers. Im surprised I cant find much on the web to help me do this.
Does anyone know a PHP script, widget, or template that could provide me this functionality? I just want to be able to input a series of questions and answers and the logical flow and be able to host it on our web server.
01-05-2011, 05:38 PM
Much too vague. What sort of questions and answers?
01-05-2011, 11:16 PM
Would this have to print an actual decision tree or just output the prediction in words?
05-19-2011, 08:00 PM
I have been looking for this, and every time I try to tackle this on my own, it breaks down after 2 levels... :confused:
I would love any assistance in figuring out how to go about it.
In generic terms, I want to have some text content (a question) and a select or dropdown box with some options. When one of those options is selected, based on the option chosen, more text and the another select or dropdown box. Based on that choice, yet another...
This chooses the best pet for you. Do you want a male or female pet?
(select or dropdown box choices = Male, Female)
(user chooses female)
Female pets are chosen on hair color. What color is your hair?
(select or dropdown box choices = Red, Blonde, Brunette, White, Other)
(user chooses White)
White pets come in 4 sizes. Which size would you prefer?
(select or dropdown box choices = Tiny, Small, Medium, Large)
...and so on based on their choices...
... If they had chosen male for their first answer, then instead of the hair color question the following would appear:
Male pets are based on height. How tall are you?
(select or dropdown box choices = Under 4ft, 4ft-5ft, 5ft-6ft, Over 6ft)
(User chooses over 6ft)
Wow, you are tall. Because you are so tall a hamster would be perfect for you.
(no choices as this ends this path.)
So, I would hope all choices/text would remain hidden if not selected, and only the path that affects the user is shown. And if possible, I would hope they would be able to go back and correct their answers if they choose a wrong option. I would like to avoid pop-ups, buttons, comboboxes, or anything along that path. I am hoping for a white screen with text only (although radio buttons instead of a dropdown box would be fine (although not ideal).
Any help would be appreciated. If this is confusing or a better example is needed, please ask.
05-19-2011, 08:37 PM
This is not difficult, but is rather tedious. In short you need to put each question and associated select list in a hidden <div> which is made visible (or style "block") in accordance with the previous choices.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
05-19-2011, 09:08 PM
Thanks for the quick response.
That is what I have done thus far. But due to my ignorance, I have run into an issue. After about 3 steps in, if I go back more than one step to "correct" a mistake, the wrong path still remains on the screen for every question beyond the immediate one.
What command am I missing to re-hide those selections, or do I have to put in a blank field that auto defaults that question back to hide, and just go back one question at a time until I get to where I need to redirect my path?
I was thinking I was doing something wrong, but perhaps I have been doing it correct all this time.
05-20-2011, 08:38 AM
At each selection you need to erase/hide all previous choices and then show only the text/select lists relevant to the selection level and selections made at that moment. That is why the coding is tedious.
So if a user makes a series of selections starting with "male" and then changes that to "female" then all the selections deriving from "male" must be reset to the default and the relevant divs hidden. As I say, tedious.
05-20-2011, 08:59 AM
I just want to be able to input a series of questions and answers and the logical flow and be able to host it on our web server.
This is fairly straight forward.
One approach is:
1) Put an onchange event handler on the dropdowns.
2) The event handler could then have a switch() block which displays only the appropriate elements and appropriate options for the current set of choices.
11-14-2011, 11:36 AM
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.