Need some help with syntax for getting the survey question/answer element

More
10 months 1 week ago - 10 months 1 week ago #188409 by lintu
Hello Folks,

I spent several hours trying to figure this out by reading the 3.x manual and going through the forum posts but could not resolve it. I now need your help please...

I upgraded from an older version to Version 3.17.13+190824 and looks like some of the code syntax has changed. As a result, this code that I had within a survey template is broken. I am trying to pre-select a radio button based on a previous selection.
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
 
            //If question G2Q1N has a selection, then pre-select the remaining radio buttons
            var qc = '{G2Q1N_SQ001}';
            if(qc == "A1"){
            	document.getElementById('answer{SID}X{GID}X{QID}SQ001_1-1').checked = true;   
			}else if(qc == "A2"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001_1-2").checked = true;      
			}
				else if(qc == "A3"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001_1-3").checked = true;    
			}
				else if(qc == "A4"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001_1-4").checked = true;   
			}
				else if(qc == "A5"){
				document.getElementById("answer{SID}X{GID}X{QID}SQ001_1-5").checked = true;     
			}
});
</script>

Could someone please help me out with the right syntax for setting the value based on the radio button ID and also for getting the value of a radio button? Thanks
Last edit: 10 months 1 week ago by lintu.

Please Log in to join the conversation.

LimeSurvey Partners
More
10 months 1 week ago #188411 by DenisChenu
In template ???
document.getElementById("answer{SID}X{GID}X{QID}SQ001_1-2").checked = true;
{SID} {GID} or {QID} can be used only survey : question or help (or script )

Else : please send a sample lss else we can not know what broken exactly …

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.

Please Log in to join the conversation.

More
10 months 1 week ago #188430 by lintu
Yes, it's in the survey question template (now called theme in V3.x). Sample sample lss attached.

Thanks for your response.
Attachments:

Please Log in to join the conversation.

More
10 months 1 week ago #188440 by lintu
Can someone help me on what the new tags should be on v3.x? The survey that I have in production is not fully functional until I resolve this issue.

Thanks

Please Log in to join the conversation.

More
10 months 1 week ago #188441 by DenisChenu
Don't do this in the theme : it's related to a specific question : right ?

Use www.limesurvey.org/limestore/extensionde...ascript-in-questions it's done for this.

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.

Please Log in to join the conversation.

More
10 months 1 week ago #188485 by lintu
Hi DenisChenu,

This change applies to over 100+ question, so I need to make the change in the custom theme that I created for this survey. Using your plugin would mean that I would need to add the script to every single question manually.

The script that I had in v2.x works but I believe the code syntax changed in v3.x and broke my script.

Please Log in to join the conversation.

More
10 months 1 week ago #188490 by DenisChenu
1. Replace `var qc = '{G2Q1N_SQ001}';` by `var qc = '{{ processString("{G2Q1N_SQ001}",1) }}';`
2. Maybe same for QID etc … (but best is to use {SGQ})

I think you can have question.qid etc ¿ in twig , unsure …

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.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now