Welcome to the LimeSurvey Community Forum

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

Star Rating value Text

  • RautenkinG
  • RautenkinG's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago - 7 years 2 months ago #157794 by RautenkinG
Star Rating value Text was created by RautenkinG
Code:
Ihre Bewertung lautet: <b><span id="starvalue"> </span></b> <script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // Identify this question
    var q1ID = {QID};
    var thisQuestion = $('#question'+q1ID);
 
    // Listener on the inputs
    $('input.radio', thisQuestion).on('click', function(e) {
 
      // The clicked value
      var value = $(this).val();
 
      // Define the text
      var insertedText= '';
      switch(value) {
        case '1':
          insertedText= 'mangelhaft';
          break;
        case '2':
          insertedText= 'ausreichend';
          break;
        case '3':
          insertedText= 'befriedigend';
          break;
        case '4':
          insertedText= 'gut';
          break;
        case '5':
          insertedText= 'sehr gut';
          break;
      }
 
      // Pipe the text to the div
      $('#starvalue').text(insertedText);  
    }); 
    });
</script>

This is my code, which i found in this forum, to show the value of the star that is clicked.

I Would prefer that this effect comes without clicking on the star, it should come on hover over the star.

I tryed several things which doesnt worked, hope someone can help!

Greetings
Steffen
Last edit: 7 years 2 months ago by RautenkinG.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago #157796 by tpartner
Replied by tpartner on topic Star Rating value Text
What LimeSurvey version are you using?

Can you attach a small sample survey containing only that question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • RautenkinG
  • RautenkinG's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #157797 by RautenkinG
Replied by RautenkinG on topic Star Rating value Text
Version is 2.67.2

I try to create such a example survey
The topic has been locked.
  • RautenkinG
  • RautenkinG's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #157799 by RautenkinG
Replied by RautenkinG on topic Star Rating value Text
do the file you need end with .lss or .lsq ?
The topic has been locked.
  • RautenkinG
  • RautenkinG's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #157800 by RautenkinG
Replied by RautenkinG on topic Star Rating value Text
Okay got it, here is the example survey!

File Attachment:

File Name: limesurvey...9353.lss
File Size:15 KB
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago #157812 by tpartner
Replied by tpartner on topic Star Rating value Text
I assume that, when the hover is removed (the mouse pointer leaves a star), you want to revert the text to that associated with last selected star.

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var q1ID = {QID};
    var thisQuestion = $('#question'+q1ID);
 
    var insertedTexts = {
      '1': 'mangelhaft',
      '2': 'ausreichend',
      '3': 'befriedigend',
      '4': 'gut',
      '5': 'sehr gut'
    };
 
    $('#starvalue').attr('data-text', '');  
 
    // Listener on the radio inputs
    $('input.radio', thisQuestion).on('click', function(e) { 
      // The clicked value
      var value = $(this).val(); 
      // Pipe the text to the div
      $('#starvalue').text(insertedTexts[value]).attr('data-text', insertedTexts[value]);  
    });
 
    // Hover events on the stars
    $('.star-rating', thisQuestion).hover(
      function() { 
        // The value
        var value = $(this).attr('data-star');   
        // Pipe the dynamic text to the div
        $('#starvalue').text(insertedTexts[value]);  
      }, function() {
        $('#starvalue').text($('#starvalue').attr('data-text'));
      }
    ); 
    });
</script>

S

File Attachment:

File Name: limesurvey...9353.lss
File Size:15 KB
ample survey attached:

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • RautenkinG
  • RautenkinG's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #157840 by RautenkinG
Replied by RautenkinG on topic Star Rating value Text
Lovely! That worked perfectly :)
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose