Welcome to the LimeSurvey Community Forum

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

Java without deactivating XSS Filter?

  • Inpanic26
  • Inpanic26's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 6 months ago #167478 by Inpanic26
Java without deactivating XSS Filter? was created 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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 6 months ago #167491 by tpartner
Replied by tpartner on topic Java without deactivating XSS Filter?
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.
  • Inpanic26
  • Inpanic26's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 6 months ago #167500 by Inpanic26
Replied by Inpanic26 on topic Java without deactivating XSS Filter?
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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 6 months ago #167504 by tpartner
Replied by tpartner on topic Java without deactivating XSS Filter?
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.
  • Inpanic26
  • Inpanic26's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 6 months ago #167510 by Inpanic26
Replied by Inpanic26 on topic Java without deactivating XSS Filter?
Worked out great. Thank you so much!
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose