JavaScript to list Options in next question based on answer to prior question

Cgandhi07Cgandhi07 DavidsonCommunity Member Qubie ✭

JavaScript to list Options in next question based on answer to prior question

Hi everyone,

I have a question that shows a list of PC names that pertains to the user taking the survey. They are required to choose options from a dropdown list for thoe PC names. I have created an embedded data called "OtherSelected" with the value of whenever Other Departmental Shared PC is selected from the dropdown list. I want it so that my next question displays the PC names where the user selected "Other Departmental Shared PC" for that PC name in list view. I am having trouble with the JavaScript. Any help would be much appreciated. Thanks!!

Tagged:

Best Answer

  • TomGTomG Raleigh, NC Wizard ✭✭✭✭✭
    edited December 2018 Accepted Answer

    Your selectors are wrong.

    There is no such thing as an input[type=dropdown]. It is select.

    Then "input:dropdown:Other Departmental Shared PC(:selected)" is wrong too. If you need to use the text to find it is the innerHTML of the selected option. It would be easier to use the value of the select (i.e. the choiceid for Other Departmental Shared PC).

    Finally, assuming this is a matrix, neither the tree traversal nor selector (label.DropdownList) are valid. You need to traverse up the table row (tr) then search down to find the label text.

    It would make it easier if you just find all the selects at the beginning of the script and base everything off that:

    var selects = jQuery("#"+this.questionId+" select");
    selects.change(function() { etc...
    

Answers

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭

    Can you post the JS you are having a problem with? A picture of what you are trying to achieve might also be helpful.

  • Cgandhi07Cgandhi07 DavidsonCommunity Member Qubie ✭
    edited December 2018

    Here it is. Not really good with JS because i've had very little experience with it

  • Cgandhi07Cgandhi07 DavidsonCommunity Member Qubie ✭
    edited December 2018
  • Cgandhi07Cgandhi07 DavidsonCommunity Member Qubie ✭

    @TomG So I created an embedded data called OtherSelected where the value is if Other Deparmental Shared PC is selected for Q7 (screenshot above). I want to take the PC names where the user selected Other Deparmental Shared PC and display that in a list view in a new question, and have one text box where they can provide a description of why they selected Other Departmental Shared PC. (Originally I was hoping to have text boxes next to each PC name where the user selected Other Departmental Shared PC but I don't know how to do that and I tried Display Logic and Carry Forward Choices).

  • Cgandhi07Cgandhi07 DavidsonCommunity Member Qubie ✭
    edited December 2018

    Thanks @TomG Really appreciate your help!

Sign In to Comment