- Posts: 11
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
6 years 8 months ago #156715
by RautenkinG
get Value from Star Rating and display the Value was created 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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10629
- Thank you received: 3696
6 years 8 months ago #156721
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic get Value from Star Rating and display the Value
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
6 years 8 months ago #156723
by RautenkinG
Replied by RautenkinG on topic get Value from Star Rating and display the Value
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10629
- Thank you received: 3696
6 years 8 months ago #156740
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic get Value from Star Rating and display the Value
This will work in the latest LS version:
Sample survey attached:
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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10629
- Thank you received: 3696
6 years 8 months ago - 6 years 8 months ago #156741
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic get Value from Star Rating and display the Value
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: 6 years 8 months ago by tpartner.
The topic has been locked.
- RautenkinG
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
6 years 8 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
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.