jquerylimesurvey

Radio question - Prefill other answer text


My institution recently upgared to Limesurvey 3.

I used to prefill a radio question containing an "Other" answer, using this js code :

<script>   
$(document).ready(function() {

    $("#question{CODE.qid} input:radio[id$='other']").trigger('click');    

});  </script>

I think that code worked with Limesurvey 2 (I am not sure anymore and I cannot test it).

I managed to solve my issue in Limesurvey 3 with this code :

<script>   
$(document).ready(function() {

    $("#question{CODE.qid} input:radio:last").trigger('click');    

});  </script>

But my question is : In Limesurvey 3, is there a way to prefill answer with the former method, eg using something like id$='other'?

EDIT: I need a jquery solution, which is used by Limesurvey.

Additionnaly, I would like to prefill (with an attribute) the text related to the "Other" answer.

Is it possible to do that ?


Solution

  • Why use jquery/javascript when you can use tool dedicated system …

    Add an hidden equation before you question, hide it and put inside

    {CODE=if(is_empty(CODE.NAOK),"-oth-",CODE.NAOK)} {CODE_other=if(is_empty(CODE.NAOK),TOKEN:ATTRIBUTE_1,CODE_other.NAOK)}

    This fix the 2 feature you need, see https://manual.limesurvey.org/Expression_Manager#Using_Assignment_Operator for reference.