Welcome to the LimeSurvey Community Forum

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

Set conditions with JavaScrip

More
7 years 10 months ago #159452 by Amal121
Hi
I want to show an Alert message using Javascript ( Alert('message')) Based on some condiotons related to other questions
If i write the conditoions if the relevance box the alert message is always shown. So i need to integrate condtions in the JS code
can i do this? and how?
The topic has been locked.
More
7 years 10 months ago #159467 by tpartner
If the JavaScript is in the question source or group description, you can use Expression Manager variables. So, maybe something like this (assuming question code "Q1" has been previously answered):

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:complete',function() {
 
    if('{Q1}' == 'A1') {
      alert('Your answer to Q1 was {Q1.shown}');
    }
  });
</script>

- www.limesurvey.org/manual/Expression_Man...#Access_to_Variables

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
More
7 years 10 months ago #159601 by Amal121
Hi
The code is not working i think {Q1.jsName} should be used. In the question source it should be something like
java563728X1027X3453.
The topic has been locked.
More
7 years 10 months ago #159609 by DenisChenu

Amal121 wrote: Hi
The code is not working i think {Q1.jsName} should be used. In the question source it should be something like
java563728X1027X3453.

The code work … when loading the page.

Maybe your explanation didn't have detail …

Else {Q1.sgq}

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
7 years 10 months ago #159612 by tpartner

The code is not working

That code IS working - sample survey attached.

File Attachment:

File Name: limesurvey...0-13.lss
File Size:15.05 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose