Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Refer to question code to move "other" option

  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 2 weeks ago #196291 by Jmantysalo
I was asked for a radiobutton element having "other" as the second last option. For one question I was able to do it by adding script
Code:
function moveUp($item) {
     $before = $item.prev();
     $item.insertBefore($before);
}
 
moveUp($('#javatbd177612X75X1738other'));

when I manually look what code the question got. Also I found that {QID} can be used instead of part "1738". But what is the code for all of the "177612X75X1738"-part? I tried {SGQA} and {SGQ} wihtout luck.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196301 by tpartner
Replied by tpartner on topic Refer to question code to move "other" option
This works for me in version 3.22.6:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    function moveUp($item) {
      $before = $item.prev();
      $item.insertBefore($before);
    }
 
    moveUp($('#javatbd{SGQ}other'));
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...4-03.lss
File Size:16 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 2 weeks ago #196320 by Jmantysalo
Replied by Jmantysalo on topic Refer to question code to move "other" option
Aa-ha! That works also in 4.x. But when I extract the code and put that in the Script-field (below the Help-field), then it does not. So {SGQ} can not be used everywhere. Thanks.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196327 by DenisChenu
Replied by DenisChenu on topic Refer to question code to move "other" option

Jmantysalo wrote: So {SGQ} can not be used everywhere.

I think it's an issue and must be reported ...

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.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago - 4 years 2 weeks ago #196328 by DenisChenu
Replied by DenisChenu on topic Refer to question code to move "other" option
Else : you can use
Code:
{QCODE.s gq a}
(no space inside sgqa ...) anywhere :)
manual.limesurvey.org/Expression_Manager#Access_to_Variables

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.
Last edit: 4 years 2 weeks ago by DenisChenu.
The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 2 weeks ago #196336 by Jmantysalo
Replied by Jmantysalo on topic Refer to question code to move "other" option
I do not undestand. Putting just alert({QID}); to script field of a question gives an alert, but nothing like {QCODE}, {Qcode.sgqa} etc. do not work. Can you make an example survey?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196351 by DenisChenu
Replied by DenisChenu on topic Refer to question code to move "other" option
I try to make a sample survey but don't seems to work for me
16090: No javascript mantis issue


You can try

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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago - 4 years 2 weeks ago #196355 by tpartner
Replied by tpartner on topic Refer to question code to move "other" option
When is that JS loaded?

Maybe it should be wrapped in

Code:
$(document).ready(function() {...});

or

Code:
$(function() { ... });

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 2 weeks ago by tpartner.
The topic has been locked.
  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
4 years 2 weeks ago #196361 by Jmantysalo
Replied by Jmantysalo on topic Refer to question code to move "other" option
There reads "This optional script field will be wrapped, so that the script is correctly executed after the question is on the screen.", so there should be no need to manually write a wrapper.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 week ago #196392 by DenisChenu
Replied by DenisChenu on topic Refer to question code to move "other" option
+1 for @Jmantysalo

@tpartner : even with wrapper : "i just want to log something" are not in source code :)

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.

Lime-years ahead

Online-surveys for every purse and purpose