Set conditions with JavaScrip

More
1 month 1 week ago #159452 by Amal121
Amal121 created the topic: Set conditions with JavaScrip
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?

Please Log in to join the conversation.

More
1 month 1 week ago #159467 by tpartner
tpartner replied the 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):

<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

Please Log in to join the conversation.

More
1 month 5 days ago #159601 by Amal121
Amal121 replied the 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.

Please Log in to join the conversation.

More
1 month 5 days ago #159609 by DenisChenu
DenisChenu replied the 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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 month 5 days ago #159612 by tpartner
tpartner replied the 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.
Attachments:
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!