- Posts: 4
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<div style="width:100%;"> <div style="width:30%; float:left; margin-left: 2%; margin-right:1%"> <a href="javascript:selectface(0);" onclick="$('form#limesurvey').submit();"><img class="face num0" src="https://localhost/limesurvey/imagenes/imagen1.jpeg" width="100%" /></a></div> <div style="width:30%; float:left; margin-left: 2%; margin-right:1%"> <a href="javascript:selectface(1);" onclick="$('form#limesurvey').submit();"><img class="face num1" src="https://localhost/limesurvey/imagenes/imagen2.jpeg" width="100%" /></a></div> <div style="width:30%; float:left; margin-left: 2%; margin-right:1%"> <a href="javascript:selectface(2);" onclick="$('form#limesurvey').submit();"><img class="face num2" src="https://localhost/limesurvey/imagenes/imagen3.jpeg" width="100%" /></a></div> </div> <script type="text/javascript" charset="utf-8"> function selectface(face) { $('.face').removeClass('selected'); $('#question5 input.radio:eq('+face+')').attr('checked', true); $('.num'+face).addClass('selected'); } $(document).ready(function() { $('#question5 .survey-question-answer ').hide(); $('#question5 .questionhelp ').hide(); $( ‘#question5 + qid + ‘ input.radio’ ).hide(); selectface($('#question5 input.radio:checked').val() - 1); }); // Hide the radio buttons $( ‘#question’ + qid + ‘ input.radio’ ).hide(); $( '#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 + '' }); } }); // 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 + '' }); } }); </script> <style type="text/css"> .face { border:0px solid white; } .selected { border:4px solid #cc0000; }</style>
<div style="width:100%;"> <div style="width:30%; float:left; margin-left: 2%; margin-right:1%"> <a href="javascript:selectface(0);" onclick="$('form#limesurvey').submit();"><img class="face num0" src="https://localhost/limesurvey/imagenes/imagen1.jpeg" width="100%" /></a></div> <div style="width:30%; float:left; margin-left: 2%; margin-right:1%"> <a href="javascript:selectface(1);" onclick="$('form#limesurvey').submit();"><img class="face num1" src="https://localhost/limesurvey/imagenes/imagen2.jpeg" width="100%" /></a></div> <div style="width:30%; float:left; margin-left: 2%; margin-right:1%"> <a href="javascript:selectface(2);" onclick="$('form#limesurvey').submit();"><img class="face num2" src="https://localhost/limesurvey/imagenes/imagen3.jpeg" width="100%" /></a></div> </div> <script type="text/javascript" charset="utf-8"> function selectface(face) { $('.face').removeClass('selected'); $('#question4 input.radio:eq('+face+')').attr('checked', true); $('.num'+face).addClass('selected'); $( '#question' + qid + ' input.radio' ).hide(); } $(document).ready(function() { $('#question4 .survey-question-answer ').hide(); $('#question4 .questionhelp ').hide(); selectface($('#question69 input.radio:checked').val() - 1); } ); </script> <style type="text/css"> .face { border:0px solid white; } .selected { border:4px solid #cc0000; }</style>
<div style="width:100%;"> <div style="float:left; margin-left: 2%; margin-right:1%"> <img src="https://localhost/limesurvey/imagenes/imagen1.jpeg" /> </div> <div style="float:left; margin-left: 2%; margin-right:1%"> <img src="https://localhost/limesurvey/imagenes/imagen2.jpeg" /> </div> <div style="float:left; margin-left: 2%; margin-right:1%"> <img src="https://localhost/limesurvey/imagenes/imagen3.jpeg" /> </div> </div> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Call the radioImages function with the question ID radioImages(QQ); function radioImages(qID) { // Hide radio list $('#question'+qID+' li[id^="javatbd"]:first').parent().hide(); // Add some IDs and classes $('#question'+qID+' img').each(function(i){ $(this).attr('id','img-'+qID+'-'+i).addClass('clickableImage'); }); // Set initial "selected" classe (in case a respondent returns to the page) if($('#question'+qID+' input.radio:checked').length > 0) { var radioIndex = $('#question'+qID+' input.radio:checked').index('input.radio'); $('#question'+qID+' .clickableImage:eq('+radioIndex+')').addClass('clickableImageSelected'); } // Hover effects $('#question'+qID+' img').hover( function () { $(this).addClass('clickableImageHover'); }, function () { $(this).removeClass('clickableImageHover'); } ); // Click events $('#question'+qID+' .clickableImage').click(function(){ $('#question'+qID+' .clickableImageSelected').removeClass('clickableImageSelected'); $(this).addClass('clickableImageSelected'); var imgIndex = $(this).attr('id').split(qID+'-')[1]; $('#question'+qID+' input.radio:eq('+imgIndex+')').click(); // Submit the page if($('#movesubmitbtn').length > 0) { document.limesurvey.move.value = 'movesubmit'; } else { document.limesurvey.move.value = 'movenext'; } document.limesurvey.submit(); }); } }); </script>
.clickableImage { border: 2px solid transparent; } .clickableImageHover { border-color: #66FF66; } .clickableImageSelected { border-color: #009900; }
// Click events $('#question'+qID+' .clickableImage').click(function(){ $('#question'+qID+' .clickableImageSelected').removeClass('clickableImageSelected'); $(this).addClass('clickableImageSelected'); var imgIndex = $(this).attr('id').split(qID+'-')[1]; $('#question'+qID+' input.radio:eq('+imgIndex+')').click(); // Submit the page if($('#movesubmitbtn').length > 0) { document.limesurvey.move.value = 'movesubmit'; } else { document.limesurvey.move.value = 'movenext'; } document.limesurvey.submit(); }); } }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('.star-rating').click(function(){ if($('#movesubmitbtn').length > 0) { document.limesurvey.move.value = 'movesubmit'; } else { document.limesurvey.move.value = 'movenext'; } document.limesurvey.submit(); }); }); </script>
tpartner wrote: Okay, this code will auto-submit the page but you can just comment out that line if you don't want it to.
Add the following to the source of the question and Replace "QQ" with the question ID :Code:<div style="width:100%;"> <div style="float:left; margin-left: 2%; margin-right:1%"> <img src="https://localhost/limesurvey/imagenes/imagen1.jpeg" /> </div> <div style="float:left; margin-left: 2%; margin-right:1%"> <img src="https://localhost/limesurvey/imagenes/imagen2.jpeg" /> </div> <div style="float:left; margin-left: 2%; margin-right:1%"> <img src="https://localhost/limesurvey/imagenes/imagen3.jpeg" /> </div> </div> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Call the radioImages function with the question ID radioImages(QQ); function radioImages(qID) { // Hide radio list $('#question'+qID+' li[id^="javatbd"]:first').parent().hide(); // Add some IDs and classes $('#question'+qID+' img').each(function(i){ $(this).attr('id','img-'+qID+'-'+i).addClass('clickableImage'); }); // Set initial "selected" classe (in case a respondent returns to the page) if($('#question'+qID+' input.radio:checked').length > 0) { var radioIndex = $('#question'+qID+' input.radio:checked').index('input.radio'); $('#question'+qID+' .clickableImage:eq('+radioIndex+')').addClass('clickableImageSelected'); } // Hover effects $('#question'+qID+' img').hover( function () { $(this).addClass('clickableImageHover'); }, function () { $(this).removeClass('clickableImageHover'); } ); // Click events $('#question'+qID+' .clickableImage').click(function(){ $('#question'+qID+' .clickableImageSelected').removeClass('clickableImageSelected'); $(this).addClass('clickableImageSelected'); var imgIndex = $(this).attr('id').split(qID+'-')[1]; $('#question'+qID+' input.radio:eq('+imgIndex+')').click(); // Submit the page if($('#movesubmitbtn').length > 0) { document.limesurvey.move.value = 'movesubmit'; } else { document.limesurvey.move.value = 'movenext'; } document.limesurvey.submit(); }); } }); </script>
Then add this to the end of template.css (your code had styles embedded in the <body> of the page which is a no-no):Code:.clickableImage { border: 2px solid transparent; } .clickableImageHover { border-color: #66FF66; } .clickableImageSelected { border-color: #009900; }