Execute Jquery after Relevance Equation executed

Mehr
5 Monate 14 Minuten her #168884 von MadhuraBL
MadhuraBL erstellte das Thema 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.
Anhang:

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 4 Wochen her - 4 Monate 4 Wochen her #168889 von Joffm
Joffm antwortete auf das Thema: 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


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Letzte Änderung: 4 Monate 4 Wochen her von Joffm.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 4 Wochen her #168894 von MadhuraBL
MadhuraBL antwortete auf das Thema: 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.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 4 Wochen her #168908 von Joffm
Joffm antwortete auf das Thema: 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.

Dateianhang:

Dateiname: limesurvey...5-18.lss
Dateigröße:21 KB


Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Anhang:
Folgende Benutzer bedankten sich: MadhuraBL

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 3 Wochen her #168941 von MadhuraBL
MadhuraBL antwortete auf das Thema: Execute Jquery after Relevance Equation executed
Thanks Joffm, this is exactly what I wanted.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
4 Monate 3 Wochen her - 4 Monate 3 Wochen her #168948 von MadhuraBL
MadhuraBL antwortete auf das Thema: 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.
Letzte Änderung: 4 Monate 3 Wochen her von MadhuraBL.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha