Welcome to the LimeSurvey Community Forum

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

get Value from Star Rating and display the Value

  • RautenkinG
  • RautenkinG's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 months ago #156715 by RautenkinG
Hey Guys,

This is pretty much my question

I tried it to do it like this but my attempt failed.

Can someone give me short help where to Add the <div> in the template editor and where to add the .js


thanks in advance
Steffen
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #156721 by tpartner
Insert both after your question text, using the source mode in the editor.

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 3 months ago #156723 by RautenkinG
Replied by RautenkinG on topic get Value from Star Rating and display the Value
Thanks for the response,

i tried it to placed it after my Question, still doesnt work for me.

I poste a picture with this post
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #156740 by tpartner
This will work in the latest LS version:

Code:
Q1...
<div id="starvalue"></div>
<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= 'One';
          break;
        case '2':
          insertedText= 'Two';
          break;
        case '3':
          insertedText= 'Three';
          break;
        case '4':
          insertedText= 'Four';
          break;
        case '5':
          insertedText= 'Five';
          break;
      }
 
      // Pipe the text to the div
      $('#starvalue').text(insertedText);  
    }); 
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...8861.lss
File Size:13 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago - 7 years 3 months ago #156741 by tpartner
Or, this, which will work slightly faster...

Code:
Q1...
<div id="starvalue"></div>
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // Identify this question
    var q1ID = {QID};
    var thisQuestion = $('#question'+q1ID);
 
    // Define the text
    var insertedText = {
      1: 'Text for one star',
      2: 'Text for two stars',
      3: 'Text for three stars',
      4: 'Text for four stars',
      5: 'Text for five stars'
    }
 
    // Listener on the inputs
    $('input.radio', thisQuestion).on('click', function(e) {
 
      // Pipe the text to the div
      $('#starvalue').text(insertedText[$(this).val()]);  
    }); 
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 3 months ago by tpartner.
The topic has been locked.
  • RautenkinG
  • RautenkinG's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 months ago #156782 by RautenkinG
Replied by RautenkinG on topic get Value from Star Rating and display the Value
That worked perfectly!

Would you mind to tell me how can i achieve this the same way without clicking on it, so only Hover would be enough?

i tried

$('input.radio', thisQuestion).on('mouseover', function(e) {

and

$('input.radio', thisQuestion).hover( function(e) {

Sadly both didnt worked with it.

Greetings
Steffen
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose