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.
Code:
<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
{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 support
-
Plugins, theme and development
. I don't answer to private message.
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.
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.
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 support
-
Plugins, theme and development
. I don't answer to private message.