Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Execute Jquery after Relevance Equation executed

  • MadhuraBL
  • MadhuraBL's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 11 months ago #168884 by MadhuraBL
Hi, I am trying to add a textarea for a single option in an Array question.

To achieve this,
1. I added 2 questions: 1-> Array; 2 -> LongFreeText
2. Added <span id="subQn2describe"> tag for Array subquestion where I need TextBox to appear

3. Added JavaScript for the Long free Text to hide this question but display only the textbox after Sub question 2 (Refer js code below)


Code:
       <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                var htmml = $("<div />").append($("#answer{SID}X{GID}X{QID}")).html();
                $('#subQn2describe').after(htmml);
                $('#question{QID}').hide();
            });
       </script>

This works just perfect (with text typed in textbox stored in backend).
But does not work when a RELEVANCE EQUATION is assigned to the questions (need RelEquation on both questions)

The custom js code is executed when survey is loaded, but is overwritten when Relevance Equation is executed.

My Survey structure: (display group by group)
Group 1:
Qn1: Name; Qn2: Gender; Qn3: Date of Birth
Group 2: (display group 3 only if age is less than 18yrs)
Qn1: Array question -> Relevance equation: (floor((time() - strtotime(Qn3)) / (60 * 60 * 24 * 365)) < 18)
Qn2: If Option 2, please describe -LongFreeText -> Relevance equation: (floor((time() - strtotime(Qn3)) / (60 * 60 * 24 * 365)) < 18) ( .hide() in js code)

Any suggestion on how to achieve this with Relevance Equation?

Note: with relevance eqn, my js code is overwritten and questions appear in the default way. i.e., Array Qn1 and Textarea Qn2 as separate questions.

Thanks in advance.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 11 months ago - 5 years 11 months ago #168889 by Joffm
Hi, MadhuraBL

my first idea was:
Why didn't you set the relevance equation on the group instead on each question?
You said the entire group is not displayed if older than 18.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 years 11 months ago by Joffm.
The topic has been locked.
  • MadhuraBL
  • MadhuraBL's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 11 months ago #168894 by MadhuraBL
Replied by MadhuraBL on topic Execute Jquery after Relevance Equation executed
Hi Joffm,
Thanks for your reply. It somehow missed my mind that I could set relevance equation on group!

I just tried setting relevance equation on group and set RelEqn to "1" for all questions in the group. Still no luck! my custom code is still overwritten.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 10 months ago #168908 by Joffm
Hi,
here is a working example.
Of course it is a tpartner's script.

At the moment the open option is at the end, but you seem to be experienced in javascript, so you might adapt.


And in the sample there is also the relevance.

File Attachment:

File Name: limesurvey...5-18.lss
File Size:21 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: MadhuraBL
The topic has been locked.
  • MadhuraBL
  • MadhuraBL's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 10 months ago #168941 by MadhuraBL
Replied by MadhuraBL on topic Execute Jquery after Relevance Equation executed
Thanks Joffm, this is exactly what I wanted.
The topic has been locked.
  • MadhuraBL
  • MadhuraBL's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 10 months ago - 5 years 10 months ago #168948 by MadhuraBL
Replied by MadhuraBL on topic Execute Jquery after Relevance Equation executed
Hi Joffm, I updated your script to adapt my requirement and everything was working fine, until I changed the Relevance Equation of the group to my original Regular Expression: (floor((time() - strtotime(Qn3)) / (60 * 60 * 24 * 365)) < 18).
I reverted the RelEqn back like in your sample code: A1<18 and the script worked! I then tested with my previous java script code with RelEqn A1<18 and that works as well.

So it was the Regular Expression in RelEqn causing the issue! Show/Hide of the groups with regular expression works perfectly fine, it's only the custom script that is overwritten to default display, with Regular Expression as Relevance Equation. Strange really!


Created Equation type question(Age) with regular expression in Logic.
Used Age<18 as Relevance equation for all other age related questions.


Thanks very much for your help and time, really appreciate it.
Last edit: 5 years 10 months ago by MadhuraBL.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose