Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Filling hidden question with previous answers

Filling hidden question with previous answers 3 years 5 months ago #57487

  • AndrejL
  • AndrejL's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 35
  • Karma: 1
Hi!

I'm not familiar with js, so I need help from someone who does.

I will not get into details of my questionnaire because it's not relevant. But following script could solve some of my problems.

Let's say I have a hidden multiple question which I want to fill depending on answers from previous questions.

For example: if respondents checks answer 3 in Q1 I want answer 5 in Q2 to be checked. Both questions are multiple and q2 in hidden.

Thank you,

Andrej
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57497

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
Are both questions on the same page?
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57502

  • AndrejL
  • AndrejL's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 35
  • Karma: 1
no
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57505

  • yohann
  • yohann's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Thank you received: 1
  • Karma: 1
Hello, I'm running in the same issue as you do, except that i want to fill the question with some custom tokens attribute.
it works well if the question is displayed, but not if the question is hidden.

i use the display "one question at once" so the hidden question is never displayed and the jquery is never executed.

On previous versions of lime survey i used a php hack to fill the answers, but when i see all greats evolutions limesurvey had for the last year, i prefer to have a vanilla limesurvey to keep limesurvey up to date easily.
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57507

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
no
Well, no point in wasting time on pleasantries eh? You will need to use {INSERTANS}. I would need more details to give you an example but there are many posts on the subject if you search the forum.
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57508

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
i use the display "one question at once" so the hidden question is never displayed and the jquery is never executed.
JavaScript can only be applied to elements that exist in the DOM. In other words, the question must exist on the page.

The question can be hidden with CSS or JavaScript but NOT with the "Always hide this question" setting.
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57509

  • yohann
  • yohann's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 8
  • Thank you received: 1
  • Karma: 1
that is what i understand, but if i hide the question with javascript or css, then users will see an empty screen (because i'm displaying question by question).
i made a feature request about the "always hide this question" functionnality.
here
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57516

  • AndrejL
  • AndrejL's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 35
  • Karma: 1
tpartner wrote:
no
Well, no point in wasting time on pleasantries eh? You will need to use {INSERTANS}. I would need more details to give you an example but there are many posts on the subject if you search the forum.

Didn't mean to be rude :blush:

I searched the forum and found some example for tokens but none for other questions. At least the one that helped me solve my problem.

I have 4 questions (all multiple)in my survey (among others of course. One with answer codes 1-12, second with codes 13-20 and last one with 21-25. Later on I have question with all 25 codes combined and I would like only answers that were previously marked to be shown.

Similar to array filter but I have to use 3 questions not just one.

My idea is to have hidden question with 25 codes and I use a script to fill in the answers. Than I can use array filter function to show only answers I want.

Of course I would appreciate other solutions as well. I not really expert in LS.

Thank you,

Andrej
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57522

  • AndrejL
  • AndrejL's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 35
  • Karma: 1
I found the solution in this topic: www.limesurvey.org/en/forum/design-issues/43056-matrix-filter

I copied the survey to test the script. It worked fine till I tried to use the script in my original survey. When I update the question with following script
<script type="text/javascript">
 
    $(document).ready(function(){
 
 
       if ( '{INSERTANS:21224X115X116431}' == 'Brez odgovora' ) {   $('#javatbd21224X94X138221').hide();}
 
    });
</script>

I get this error

Error Update Question: UPDATE "lime_questions"SET type='L', title='15a_1', question='<script type="text/javascript"> $(document).ready(function(){ if ( \'{INSERTANS:21224X115X116431}\' == \'Brez odgovora\' ) { $(\'#javatbd21224X94X138221\').hide();} }); </script>', preg='', help='', gid='94', other='Y', mandatory='N'WHERE sid='21224' AND qid='13822' AND language='sl'
ERROR: syntax error at or near "{" at character 161


What am I doing wrong?

Thank you,

Andrej
The administrator has disabled public write access.

Re: Filling hidden question with previous answers 3 years 5 months ago #57524

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
Do you have the XSS filter turned off?
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.205 seconds
Donation Image