Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Much too vague. What sort of questions and answers?

  • #3
    New Coder
    Join Date
    Mar 2010
    Location
    New Jersey USA
    Posts
    81
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Would this have to print an actual decision tree or just output the prediction in words?

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    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.

  • #8
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    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.

  • #9
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •