4

Based on a flowchart noted as OPML nodes in my xhtml, I would like to dynamically (using jquery, without refreshing the page) get questions shown one by one, depending on the yes/no answer of the previous one, until a final message in the OPML is reached. For example;

Q: Do you have a pet?
A: yes

Q: Is it big?
A: yes

Q: Is it a dog?
A: yes

Final:Please note that dogs are not allowed at this event!

The mechanism is similar to the one proposed in this SO question. However it needs to be coded for each question and reply. I am looking for a way to code something at which you can trow any OPML at, and it will automagically creates that behavior.

[edit] As a readable fallback when javascript is switched off, and to avoid parsing external OPML, it might be better to use XOXO an outline microformat instead of OPML.

Community
  • 1
  • 1
newnomad
  • 1,055
  • 3
  • 11
  • 15
  • Can you provide some sample markup? – thirtydot Sep 27 '11 at 08:52
  • http://jsfiddle.net/gY3Yy/4/ It would be nice to find a way not having to repeat the same answers over and over again, something like, see step N. Just like an outliner can point to one balloon multiple times. – newnomad Sep 27 '11 at 10:36

1 Answers1

0

You could do something like this: http://jsfiddle.net/kayen/fGrT2/

HTML:

<div id="petTest">
    <fieldset>
        <legend>Do you have a pet?</legend>
        <ul>
            <li><label for=""><input type="radio" name="petstatus" value="Yes" /> Yes</label></li>
            <li><label for=""><input type="radio" name="petstatus" value="No" /> No</label></li>
        </ul>
    </fieldset>

    <fieldset>
        <legend>Is it big?</legend>
        <ul>
            <li><label for=""><input type="radio" name="petsize" value="Yes" /> Yes</label></li>
            <li><label for=""><input type="radio" name="petsize" value="No" /> No</label></li>
        </ul>
    </fieldset>

    <fieldset>
        <legend>Is it a dog?</legend>
        <ul>
            <li><label for=""><input type="radio" name="pettype" value="Yes" /> Yes</label></li>
            <li><label for=""><input type="radio" name="pettype" value="No" /> No</label></li>
        </ul>
    </fieldset>
    <fieldset>
        <legend>Please note that dogs are not allowed at this event!</legend>
    </fieldset> 
</div>

JQuery:

$("#petTest fieldset")
    .hide()
    .eq(0).show()
    .end()
    .find("input[value='Yes']")
    .click(function() {
      $(this).parents("fieldset").next().show(300);
    })
    .end()
    .find("input[value='No']")
    .click(function() {
        $(this).parents("fieldset").nextAll().hide(300, function(){
            $(this).find("input").attr("checked", false);                
        });
    });
Hannele
  • 9,301
  • 6
  • 48
  • 68
kayen
  • 4,838
  • 3
  • 19
  • 20