Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-05-2011, 03:52 PM   PM User | #1
texasboy1980
New to the CF scene

 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
texasboy1980 is an unknown quantity at this point
Looking for web based decision tree script

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.
texasboy1980 is offline   Reply With Quote
Old 01-05-2011, 04:38 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Much too vague. What sort of questions and answers?
Philip M is offline   Reply With Quote
Old 01-05-2011, 10:16 PM   PM User | #3
connollyc4
New Coder

 
Join Date: Mar 2010
Location: New Jersey USA
Posts: 74
Thanks: 11
Thanked 4 Times in 4 Posts
connollyc4 is an unknown quantity at this point
Would this have to print an actual decision tree or just output the prediction in words?
connollyc4 is offline   Reply With Quote
Old 05-19-2011, 07:00 PM   PM User | #4
Emau42
New to the CF scene

 
Join Date: May 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Emau42 is an unknown quantity at this point
Also looking for this.

I have been looking for this, and every time I try to tackle this on my own, it breaks down after 2 levels...

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...

Example:

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.
Emau42 is offline   Reply With Quote
Old 05-19-2011, 07:37 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 05-19-2011, 08:08 PM   PM User | #6
Emau42
New to the CF scene

 
Join Date: May 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Emau42 is an unknown quantity at this point
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.
Emau42 is offline   Reply With Quote
Old 05-20-2011, 07:38 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 05-20-2011, 07:59 AM   PM User | #8
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
Quote:
Originally Posted by texasboy1980 View Post
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.

Last edited by bullant; 05-20-2011 at 08:01 AM..
bullant is offline   Reply With Quote
Old 11-14-2011, 10:36 AM   PM User | #9
bl007
New to the CF scene

 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bl007 is an unknown quantity at this point
http://code.google.com/p/interactive-decision-tree/
bl007 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:28 PM.


Advertisement
Log in to turn off these ads.