Welcome to the LimeSurvey Community Forum

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

Java without deactivating XSS Filter?

More
7 years 4 months ago #167478 by Inpanic26
Hello guys,

I want to create an array question with an "Other" option at the end. I found already several ways to do that with Javascript. Unfortunately, due to safety reasons I am not allowed to deactivate the XSS Filter. Is there any other way to use Javascript (eg. in the template) and if not, is there a way to create this question without using Java?

I am using Version 2.50+ Build 160804

Thanks for yout time and help!
The topic has been locked.
More
7 years 4 months ago #167491 by tpartner
Place your JS in template.js or custom.js (depending on the LimeSurvey version)

Note that you will not be able to use placeholders like {QID}.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 4 months ago #167500 by Inpanic26
Dear tpartner,

thanks for your answer. What would I use instead {QID}? My plan was to use one of your scripts which I found in the LS forum(shown below). Would that even work or am I completly on the wrong track?

Best Regards
Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify the questions
    var q1 = $('#question'+{QID}+'');
    var q2 = $(q1).nextAll('.text-short:eq(0)');
 
    // Hide the short-text question
    $(q2).hide();
 
    // Move the hidden text input into the array
    $('th.answertext:last', q1).append($('input[type="text"]', q2));
 
    // Some styling...
    $('input[type="text"]', q1).css({
      'width': '50%'
    });
  });
</script>
 
 
The topic has been locked.
More
7 years 4 months ago #167504 by tpartner
You can hard-code the question ID. Something like this, where "9825" is your question ID:

Code:
$(document).ready(function() {
 
  if($('#question9825').length > 0) {
    // Identify the questions
    var q1 = $('#question9825');
    var q2 = $(q1).nextAll('.text-short:eq(0)');
 
    // Hide the short-text question
    $(q2).hide();
 
    // Move the hidden text input into the array
    $('th.answertext:last', q1).append($('input[type="text"]', q2));
 
    // Some styling...
    $('input[type="text"]', q1).css({
      'width': '50%'
    });
  }
});


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: Inpanic26
The topic has been locked.
More
7 years 4 months ago #167510 by Inpanic26
Worked out great. Thank you so much!
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose