Welcome to the LimeSurvey Community Forum

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

Need some help with a code snippet please

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #139822 by tpartner
Replied by tpartner on topic Need some help with a code snippet please
Denis' $('body .content') selector was just an example. The correct selector would depend on your template. Can you activate a test survey and give us a link and also attach a mockup of where you want the image?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • lintu
  • lintu's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 7 months ago - 7 years 7 months ago #139824 by lintu
Replied by lintu on topic Need some help with a code snippet please
tpartner,

Here's a link to my test assessment: Link

There are two questions on this assessment - on the first question, I am displaying two images on top of the answers by inserting code in the question.pstpl template. I want to hide these images for the 2nd question.

Thanks in advance for all your help!!
Last edit: 7 years 7 months ago by lintu.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #139833 by Joffm
Replied by Joffm on topic Need some help with a code snippet please

lintu wrote: P.S. Joffm - I exported the survey excel file as you suggested, but my custom code is not in there for me to remove as I inserted it in the template.


Hi, lintu,
of course not.
This EXCEL file is the survey structure, more or less the same as the *.lss.

What I suggested was, that you remove the picture code in columns 37 (dualscale_headerA) and 38 (dualscale_headerB) in the desired questions.
By filtering the file by question code this is done very quickly - without the JavaScript stuff.

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 7 months ago #139843 by tpartner
Replied by tpartner on topic Need some help with a code snippet please

I am displaying an image on top of the answer selections (see screenshot below) for every question. Since I have over 100+ questions, instead of adding this to each answer, I inserted my code in the question.pstpl template. Now, for select questions, I want to hide this based on the question # or question code.

Based on your test survey, something like this should qork:

Code:
<script type="text/javascript" charset="utf-8">     
  $(document).ready(function() {  
    var q = '{QUESTION_CODE}';
    if (q == 'Q1') {
      // Hide the images table      
      $('.no-more-tables-array-dual').prevAll('center:eq(0)').hide;
    }
    else { 
      // Do nothing
    }
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • lintu
  • lintu's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 7 months ago #139891 by lintu
Replied by lintu on topic Need some help with a code snippet please
Hello tpartner,
Thanks for the helpful code snippet. Unfortunately it did not work for me. I tried by placing the code both in the question template and EM.

Joffm,
I had another look in the survey structure excel file that I downloaded (attached), but for my desired question (#2) there is no picture code in columns 37 (dualscale_headerA) and 38 (dualscale_headerB) for me to remove.

File Attachment:

File Name: limesurvey...4848.txt
File Size:16 KB


A big thanks to you both!
The topic has been locked.
  • lintu
  • lintu's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 7 months ago #139892 by lintu
Replied by lintu on topic Need some help with a code snippet please
Finally success!!! The following code works for me:
Code:
            <CENTER> 
            <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> 
            <TR> 
            <TD ALIGN=CENTER><img id="customimage1" src="images/current_state.jpg"></TD>
            </TD> 
            </TABLE></CENTER> 
 
<script>
var q = '{QUESTION_CODE}';
 
      if (q == 'q1') {
            //Hide the image for this question
            document.getElementById("customimage1").style.display = 'none';
      }
</script>

Thanks again for all your support - really appreciate it!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose