Welcome to the LimeSurvey Community Forum

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

Clickable Image as Answer - change label

  • TwentyTwo
  • TwentyTwo's Avatar Topic Author
  • New Member
  • New Member
More
13 years 1 month ago #80214 by TwentyTwo
Replied by TwentyTwo on topic Clickable Image as Answer - change label
I have tested it as well with all browsers, also Chrome.
Please note - it is the third screen/question, the first is just fine.
The second screen doesn't matter.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago - 13 years 1 month ago #80236 by Mazi
Replied by Mazi on topic Clickable Image as Answer - change label
Thanks for clarifying. Indeed, only the first question works fine.

Hard to say why at the first one it works fine. Maybe it's just some wrong IDs or the like, I can't say. Tony (tpartner) is the JavaScript expert, maybe he can help you out.

Best regards/Beste Grüße,
Dr. Marcel Minke
survey-consulting.com
offlinesurveys.com
Feel free to contact me by email for professional LimeSurvey support!
Last edit: 13 years 1 month ago by Mazi.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago - 13 years 1 month ago #80298 by tpartner
Replied by tpartner on topic Clickable Image as Answer - change label
Expression Manager in 1.92 is screwing up your (perfectly valid) JavaScript.

With EM, you need a space after all opening curly braces and before all closing curly braces.

So, for example, this:
Code:
$(this).css({'border':'10px solid ' + checkedBorder + ''});

Needs to be this this:
Code:
$(this).css({ 'border':'10px solid ' + checkedBorder + '' });

Try this to you script supplied above:
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() { 
 
        // Insert the images into the labels 
        $( 'label[for="answer65848X42X146A1"]' ).html('<img title="Option 1" src="../plaatjes/smile.jpg"/>'); 
        $( 'label[for="answer65848X42X146A2"]' ).html('<img title="Option 2" src="../plaatjes/smile.jpg"/>'); 
 
        // A function to handle the behavior of images in select/radio questions 
        function labelImageEffects(qid) { 
 
            ////////// Set your border colors here ///////// 
            var uncheckedBorder = '#fff'; 
            var checkedBorder = '#0F0'; 
            var hoverBorder = '#066'; 
            /////////////////////////////////////////////// 
 
            // Find the initial state of the radio buttons and style labels accordingly 
            $( '#question' + qid + ' td.answer label.answertext' ).each(function(i) { 
                var id = $( this ).attr('for'); 
                if ( $( '#question' + qid + ' td.answer input#' + id + '' ).attr('checked') == true ) { 
                    $(this).css({ 'border':'10px solid ' + checkedBorder + '' }); 
                } 
                else { 
                    $(this).css({ 'border':'10px solid ' + uncheckedBorder + '' }); 
                } 
            }); 
 
            // Hide the radio buttons 
            $( '#question' + qid + ' input.radio' ).hide(); 
 
            // Label pointer and width styles 
            // $( '#question' + qid + ' td.answer label.answertext' ).css({ 'cursor':'pointer', 'width':'auto' }); 
            $( '#question' + qid + ' td.answer label.answertext' ).css({ 'cursor':'pointer', 'width':'auto', 'height':'auto', 'display':'inline-block' });
 
            // Dennis - extra for the inline-block outline
            // Fix list text-indent 
            $( '#question' + qid + ' li' ).css({ 'text-indent':'0' });
 
 
            // Hover label border styles 
            $( '#question' + qid + ' td.answer label.answertext' ).hover(function () { // On mouseover 
                var id = $( this ).attr('for'); 
                $(this).css({ 'border':'10px solid ' + hoverBorder + '' }); 
            },  
            function () { // On mouseout 
                var id = $( this ).attr('for'); 
                if ( $( '#question' + qid + ' td.answer input#' + id + '' ).attr('checked') == true ) { 
                    $(this).css({ 'border':'10px solid ' + checkedBorder + '' }); 
                } 
                else { 
                    $(this).css({ 'border':'10px solid ' + uncheckedBorder + '' }); 
                } 
 
            }); 
 
            // Checked label border styles 
            $( '#question' + qid + ' td.answer label.answertext' ).click(function (event) { 
 
                $( '#question' + qid + ' td.answer label.answertext' ).css({ 'border':'10px solid ' + uncheckedBorder + '' }); 
                $( this ).css({ 'border':'10px solid ' + checkedBorder + '' }); 
 
                // IE hack to check the affiliated radio button 
                var id = $( this ).attr('for'); 
                $( '#question' + qid + ' td.answer input#' + id + '' ).attr('checked', true); 
 
            }); 
 
        } 
 
        // Call the image effects function 
        labelImageEffects(146); 
 
    }); 
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 13 years 1 month ago by tpartner.
The following user(s) said Thank You: TwentyTwo
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago #80304 by Mazi
Replied by Mazi on topic Clickable Image as Answer - change label

tpartner wrote: Expression Manager in 1.92 is screwing up your (perfectly valid)JavaScript.

With EM, you need a space after all opening curly braces and before all closing curly braces.

Tony, I think we should either put a warning at the JavaScript workarounds page or overwork the Workarounds listed there (or both)!?

What do you think?

Best regards/Beste Grüße,
Dr. Marcel Minke
survey-consulting.com
offlinesurveys.com
Feel free to contact me by email for professional LimeSurvey support!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago #80308 by tpartner
Replied by tpartner on topic Clickable Image as Answer - change label
I will go through my workarounds but I would prefer that well-formed, valid JavaScript worked.

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
13 years 1 month ago #80311 by mkb
Hi,

I would be very interested in this.... are there instructions for multiple choice. Once the bug they found from my survey gets fixed I would like to implement this.

Thanks,
M
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago #80312 by Mazi
Replied by Mazi on topic Clickable Image as Answer - change label

tpartner wrote: I will go through my workarounds but I would prefer that well-formed, valid JavaScript worked.

I agree, especially since valid but not working JS is irritating ad frustrating for the users.
How about showing a warning on save if the "<script" + "type=javascript" is detected to let the users know they have to add spaces?

I think that's the least we should do?!

Best regards/Beste Grüße,
Dr. Marcel Minke
survey-consulting.com
offlinesurveys.com
Feel free to contact me by email for professional LimeSurvey support!
The topic has been locked.
  • TwentyTwo
  • TwentyTwo's Avatar Topic Author
  • New Member
  • New Member
More
13 years 1 month ago #80331 by TwentyTwo
Replied by TwentyTwo on topic Clickable Image as Answer - change label
Many thanks tpartner!
You once helped me providing this Javascript and now with the solution for have it working again in 1.92!!
Much appreciated!!
The topic has been locked.
  • TwentyTwo
  • TwentyTwo's Avatar Topic Author
  • New Member
  • New Member
More
13 years 1 month ago #80424 by TwentyTwo
Replied by TwentyTwo on topic Clickable Image as Answer - change label
@mkb
I have changed the css a bit for multi response
screen 4 in the example: demolink
you can download the lss here
The topic has been locked.
More
13 years 1 month ago #80430 by mkb
This is GREAT thanks!!
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago #80477 by Mazi
Replied by Mazi on topic Clickable Image as Answer - change label
Thanks TwentyTwo, we are looking forward to more examples.

Best regards/Beste Grüße,
Dr. Marcel Minke
survey-consulting.com
offlinesurveys.com
Feel free to contact me by email for professional LimeSurvey support!
The topic has been locked.
More
11 years 6 months ago #102489 by Luk01
Replied by Luk01 on topic Clickable Image as Answer - change label
Unfortunately all links provided here are not working now ...
Can anyone pls share an *.lsq file with Clickable Image question?
It would be way easier to understand the logic behind that with live working example....
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose