Set conditions with JavaScrip

More
4 years 3 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
4 years 3 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):

<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.
More
4 years 3 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
4 years 3 months ago #159609 by DenisChenu

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.
More
4 years 3 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 KB

Cheers,
Tony Partner

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

Start now!

Just create your account and start using Limesurvey today.

Register now