Execute Jquery after Relevance Equation executed

More
3 days 5 hours ago #168884 by MadhuraBL
MadhuraBL created the topic: Execute Jquery after Relevance Equation executed
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)


       <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.
Attachments:

Please Log in or Create an account to join the conversation.

More
3 days 2 hours ago - 3 days 2 hours ago #168889 by Joffm
Joffm replied the topic: Execute Jquery after Relevance Equation executed
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
Last Edit: 3 days 2 hours ago by Joffm.

Please Log in or Create an account to join the conversation.

More
3 days 2 hours ago #168894 by MadhuraBL
MadhuraBL replied the 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.

Please Log in or Create an account to join the conversation.

More
2 days 21 hours ago #168908 by Joffm
Joffm replied the topic: Execute Jquery after Relevance Equation executed
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
Attachments:
The following user(s) said Thank You: MadhuraBL

Please Log in or Create an account to join the conversation.

More
1 day 11 minutes ago #168941 by MadhuraBL
MadhuraBL replied the topic: Execute Jquery after Relevance Equation executed
Thanks Joffm, this is exactly what I wanted.

Please Log in or Create an account to join the conversation.

More
7 hours 43 minutes ago - 6 hours 49 minutes ago #168948 by MadhuraBL
MadhuraBL replied the 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: 6 hours 49 minutes ago by MadhuraBL.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!