Welcome to the LimeSurvey Community Forum

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

Set conditions with JavaScrip

  • Amal121
  • Amal121's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 5 months ago #159452 by Amal121
Set conditions with JavaScrip was created 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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 5 months ago #159467 by tpartner
Replied by tpartner on topic Set conditions with JavaScrip
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>

- manual.limesurvey.org/Expression_Manager#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.
  • Amal121
  • Amal121's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 5 months ago #159601 by Amal121
Replied by Amal121 on topic Set conditions with JavaScrip
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.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 5 months ago #159609 by DenisChenu
Replied by DenisChenu on topic Set conditions with JavaScrip

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 service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 5 months ago #159612 by tpartner
Replied by tpartner on topic Set conditions with JavaScrip

The code is not working

That code IS working - sample survey attached.

File Attachment:

File Name: limesurvey...0-13.lss
File Size:15 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.

Lime-years ahead

Online-surveys for every purse and purpose