Welcome to the LimeSurvey Community Forum

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

Modify Image Attribute based on List Selection

  • dweisser
  • dweisser's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 2 months ago #102853 by dweisser
Replied by dweisser on topic Modify Image Attribute based on List Selection
Completely works. You absolutely rock!
Happy holidays from Nebraska TPartner.
David
The topic has been locked.
  • dweisser
  • dweisser's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago #104882 by dweisser
Replied by dweisser on topic Modify Image Attribute based on List Selection
Hey T,
Any chance you have insight into how to modify the image attribute using a multi-select question?

If my question is 1628 and my subquestions are sq001, sq002 and sq003, I'm not sure how to adjust to accommodate this structure...as well as the fact that instead of radio buttons and dropdowns, they are check boxes.

If you could point me int eh right direction, I'd sure appreciate it.
Thanks as always,
David
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #104903 by tpartner
Replied by tpartner on topic Modify Image Attribute based on List Selection
I'm not sure how that would work if multiple checked boxes are possible.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • dweisser
  • dweisser's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago #104914 by dweisser
Replied by dweisser on topic Modify Image Attribute based on List Selection
I would like to show an image for each check box....
So, up to three images could show if there are three subquestions. I think the logic is the same, but instead of #question1488, should it be something like #question1488SQ001. Instead of input.radio:checked').attr('value') == 'Y', should it input.checkbox:checked').attr('value') == 'True'?

Code:
$(document).ready(function(){
 
  // Initial setting
  if($('#question1488 input.radio:checked').attr('value') == 'Y') {
    $('#variableimage1615').attr('src', 'http://www.domain.com/surveyassets/images/y1488_1.png');
  }
  if($('#question1488 input.radio:checked').attr('value') == 'N') {
    $('#variableimage1615').attr('src', 'http://www.domain.com/surveyassets/images/blank1x1.png');
  }  
 
  // Listener on the radios
  $('#question1488 input.radio').click(function(event){
    var clickedvalue = $(this).attr('value');
    if(clickedvalue == 'Y') {
      $('#variableimage1488').attr('src', 'http://www.domain.com/surveyassets/images/y1488_1.png');
    }
    if(clickedvalue == 'N') {
      $('#variableimage1488').attr('src', 'http://www.domain.com/surveyassets/images//blank1x1.png');
    }    
  });
});
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #104981 by tpartner
Replied by tpartner on topic Modify Image Attribute based on List Selection
You will need to look for the "checked" property on the check-boxes.

There will certainly be more elegant ways to do it but this script should be fairly easy to follow.

Assumptions...
- Survey ID - 111111
- Group ID - 222
- Question ID - 333
- Subqestion codes - SQ001, SQ002, SQ003
- Image IDs - variableimage1, variableimage2, variableimage3

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function(){
 
    // Define the image sources
    var img1Original = $('#variableimage1').attr('src');
    var img2Original = $('#variableimage2').attr('src');
    var img3Original = $('#variableimage3').attr('src');    
    var img1New = 'http://www.domain.com/surveyassets/images/image_1_new.png';
    var img2New = 'http://www.domain.com/surveyassets/images/image_2_new.png';
    var img3New = 'http://www.domain.com/surveyassets/images/image_3_new.png';
 
    // Initial settings
    if($('#answer111111X222X333SQ001').is(':checked')) {
      $('#variableimage1').attr('src', img1New);
    }
    if($('#answer111111X222X333SQ002').is(':checked')) {
      $('#variableimage2').attr('src', img2New);
    }
    if($('#answer111111X222X333SQ003').is(':checked')) {
      $('#variableimage3').attr('src', img3New);
    }
 
    // Listeners on the 3 checkboxes
    $('#answer111111X222X333SQ001').change(function(event) {
      if($(this).is(':checked')) {
        $('#variableimage1').attr('src', img1New);
      }
      else {
        $('#variableimage1').attr('src', img1Original);
      }
    });
    $('#answer111111X222X333SQ002').change(function(event) {
      if($(this).is(':checked')) {
        $('#variableimage2').attr('src', img2New);
      }
      else {
        $('#variableimage2').attr('src', img2Original);
      }
    });
    $('#answer111111X222X333SQ003').change(function(event) {
      if($(this).is(':checked')) {
        $('#variableimage3').attr('src', img3New);
      }
      else {
        $('#variableimage3').attr('src', img3Original);
      }
    });
  });
</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.
  • dweisser
  • dweisser's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
10 years 1 month ago #105055 by dweisser
Replied by dweisser on topic Modify Image Attribute based on List Selection
Once again, my sincerest thanks. Works beautifully.
David
The topic has been locked.
More
9 years 10 months ago #108294 by xkdax
hi...
i'm completely new to this...
would you explain how to call ansd position this funtion in the template itself?

i'm not trying to show an image, but to show text based on an array with the chosen value as key...
so when a user fills in a number in a textfield (= a course number), he/she gets - as a sort of check - the related text (= the course name)

is this the way to do that? or is there another way to do this without customizing the template?

thx
kristof
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 10 months ago #108315 by tpartner
Replied by tpartner on topic Modify Image Attribute based on List Selection
Here are some instructions on how to use scripts - manual.limesurvey.org/Workarounds:_Manip....29_in_LimeSurvey.3F


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose