TOPIC: Using previous Array question responses to set following Array subquestions

Using previous Array question responses to set following Array subquestions
3 years 10 months ago #66052

Thanks Shnoulle, it worked !
I set up two listeners : one on the cell and one on the checkbox (using your code).

About the radio button Tony, I couldn't do that, I need to have checkboxes. It's an Array (Numbers) with a checkbox layout.

Another thing if you have some time (though it's not really important) :
I have Q1 which is this Array of checkboxes and Q2 which is another array depending on the results of the second column of Q1.
So Q2 rows only show when the equivalent row in Q1 column 2 is selected.
I used the following javascript code to get it to work using an hidden Multiple Options question.

It works fine when the user checks a box in Q1 column2 : it displays the line in Q2. But
I would have liked to have some kind of toggle : if the user uncheck a box in column 2 of Q1 it should hide the correspondant row in Q2.
I tried this code that fails (it doesn't do anything - display or hide - but I can't understand why !) :

Using previous Array question responses to set following Array subquestions
2 years 2 months ago #96315

Well, it only took me two years and two months to read your instructions and get round to implementing the JavaScript code that you gave me…!! (cf. your posts #58058, #58059 and my last reply #58062)

Seriously, I thought I was getting a bit out of my depth at that point and, given a number of other work and study issues that I had to sort out at the time, decided to come back to my LimeSurvey project when I could give it my full attention.

So, I’m back and 100% determined to get my LimeSurvey “Language needs analysis” up-and-running!! You’ve already given me a lot of your valuable time, Tony, but could I ask you just to help me out again with one or two issues? (hopefully you’ll see that I’m not wasting your time here).

I read to the end of the thread but think that MaLu’s case is the closest to mine, hence my new post just before her (final success) post #62558 (I've just seen that my new post has in fact been placed at the end of the thread...).

I’m now fully upgraded and running LimeSurvey 2.00+.

I set up a simple survey (‘Test’, file attached), with just one Question Group (file attached), to implement your JavaScript workaround (I checked to see if JavaScript was enabled: ‘Alert’ echo = OK)

In Question Group 1, I set up:

Q1 (an Array question with three answers (‘N/A’, ‘Important’ and ‘Priority) and four subquestions) (file attached)

qHidden (a Multiple Option question with the same four subquestions) (file attached)

Q2 (an Array question with five answers (‘I can’t’, ‘I can’t very well’, ‘I can’, ‘I can quite well’ and ‘I can very well’) and the same four subquestions) (file attached)

As per your instructions, Q2 has conditions so it is only shown if any option in qHidden is checked. Q2 also has a filter array so that only the subquestions checked in qHidden subsequently appear.

I previewed the questions individually and ran the survey and everything seemed to be OK. Time for the JavaScript code!

As you mentioned some previous edit errors (spaces and quotes) in your post #62555, I carefully copied and pasted the ‘definitive’JavaScript code that you gave to MaLu into the qHidden source (JavaScript code in .txt file attached)

I then replaced MaLu’s question IDs with those from my ‘Test’ survey, double-checking to make sure that they were right (cf. your comment about common errors).

No joy. qHidden was hidden but Q2 was not activated. I removed the ‘Hide the hidden question’ JavaScript code to see if the checkboxes in qHidden were being checked. qHidden appeared but no checkboxes were checked.

Reading your post #62539, I then thought that, with version 2.00+, it might be necessary to replace the original answer cell codes (‘001’, ‘002’, ‘003’) with ‘00A1’, ‘00A2’ and ‘00A3’, like in MaLu’s case, but, once again, no joy.

I’ve checked everything (at least I think so!) a number of times now but I really can’t see where the problem lies. Although I now understand the function of the JavaScript code, I lack the IT knowledge necessary to see if something has been deleted/omitted/displaced etc.

Please could you have a quick look at my efforts to see where I’m going wrong? (the ‘Test’ survey is not activated; do you need me to activate it?)

Thanks a million in advance!

Regards,

StuTheQ (tenacious, if nothing else..!! )

PS If you’re wondering why my question IDs are Q1:143, Q2:158 and qHidden:153, it’s because I deleted Q2 and then created it again just before writing this post.

Using previous Array question responses to set following Array subquestions
2 years 2 months ago #96318

I've updated the script to include the following features:
- Automatically identify the questions as long as the script is placed in the source of the hidden question and that question is between the two arrays
- Assign column-specific classes to the first array to make it easier to identify the "trigger" columns
- Aggregate the listener code into a common function
- Fix up the q2 row background colours after firing the check conditions function

Using previous Array question responses to set following Array subquestions
2 years 2 months ago #96393

Your "turnkey" solution works perfectly. To be honest, I was expecting JavaScript code that closely resembled the original workaround that you posted back in 2011 (post #58058) but clearly things have moved on substantially since then. I spent yesterday going through the new workaround script, trying to understand the role of the new functions (i.e. trying to advance my infinitesimally small knowledge of JavaScript!) and also playing with the code so that I can change around the "trigger" columns in Q1.

If I understand correctly:

The workaround can be used as is (i.e. no need to specify or update question IDs) whenever I want to use an Array Q(n) to set an Array Q(n+1), provided that the workaround script given is placed in the source of the hidden question inserted between the two arrays.

(Out of curiosity, but please don't answer these if you've got better things to do!:

Using previous Array question responses to set following Array subquestions
2 years 2 months ago #96394

It doesn't really supersede but is an alternative. If you use the conditions designer, a relevance rule will automatically be generated and inserted for you. Alternatively, you can write your own relevance rule with far more flexibility than the conditions designer allows. See manual.limesurvey.org/Expression_Manager...ons_and_Relevance.3F.

What is the exact role of the qHidden toggle function?

I'm not sure I understand the question. The handleHiddenInput() function checks or unchecks boxes in the hidden question as you click radios in the first array. The array filter then shows or hides the corresponding rows in the second array.

The 'Fix up the q2 row background colours' script ensures that the subquestion rows in Q2 are alternate colours, regardless of the subquestion rows checked in Q1?

Correct. When rows are shown or hidden, it just removes all of the array1 and array2 classes from the rows and then reapplies them sequentially to the visible rows.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Using previous Array question responses to set following Array subquestions
2 years 2 months ago #96397

Thanks for the useful replies (sorry to pester you ; it's just that I always like to understand stuff, if possible! But I know that's not what the forum is for... ).

It doesn't really supersede but is an alternative. If you use the conditions designer, a relevance rule will automatically be generated and inserted for you. Alternatively, you can write your own relevance rule with far more flexibility than the conditions designer allows. See manual.limesurvey.org/Expression_Ma...ons_and_Relevance.3F.

What is the exact role of the qHidden toggle function?
I'm not sure I understand the question. The handleHiddenInput() function checks or unchecks boxes in the hidden question as you click radios in the first array. The array filter then shows or hides the corresponding rows in the second array.

Yes, I'd understood that function from the original workaround. It was just the "new" (?) 'toggle' function script which intrigued me (some kind of 'reset' function between iterations?) (no reply needed!)

The 'Fix up the q2 row background colours' script ensures that the subquestion rows in Q2 are alternate colours, regardless of the subquestion rows checked in Q1?
Correct. When rows are shown or hidden, it just removes all of the array1 and array2 classes from the rows and then reapplies them sequentially to the visible rows.

Cool!!

Guess it's about time that I enrolled for JavaScript evening classes somewhere!

Thanks, Tony.

Regards,

Stu

The administrator has disabled public write access.

Using previous Array question responses to set following Array subquestions
2 years 1 month ago #97476