Welcome, Guest
Username: Password: Remember me

TOPIC: get value from star rating and display text

get value from star rating and display text 1 year 2 months ago #92437

  • adishardis
  • adishardis's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 58
  • Karma: 0
Hi, I have no clue on how to achieve this and below is my futile attempt thus far...
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
 
 var sVala = $('#question263 input:radio[name=java725987X26X263]:checked').val()
 
		 if(sVala = 1) {
				document.getElementById('stjerna').innerHTML = 'Uselt';
			}
 
 
                  if(sVala = 2) {
				document.getElementById('stjerna').innerHTML = 'inte jättebra';
                  }
 	 	  if(sVala = 3) {
				document.getElementById('stjerna').innerHTML = 'Varken eller';
                  }
 		  if(sVala = 4) {
				document.getElementById('stjerna').innerHTML = 'Ganska bra';
                  }
  		  if(sVala = 5) {
				document.getElementById('stjerna').innerHTML = 'Föredömligt';
                  }
});
</script>

Please help a friend in need :)
/Adam
The administrator has disabled public write access.

Re: get value from star rating and display text 1 year 2 months ago #92453

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Adam, where do you want to display the text? Can you provide a mockup?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: get value from star rating and display text 1 year 2 months ago #92455

  • adishardis
  • adishardis's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 58
  • Karma: 0
starratingTEXT.png


So I gather that I would insert a div (id=stjerna) in the question area and css it to show in the right place. Though it would be ok to have the text to the left as well!

Thanks for taking time to look into this!!

/Adam
The administrator has disabled public write access.

Re: get value from star rating and display text 1 year 2 months ago #92536

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Try this:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// Identify the question
		var q1 = $('#question{QID}');
 
		// A listener on the stars
		$('.star-rating', q1).click(function () {
 
			// The clicked value
			var value = $(this).text();
 
			// Define the text
			var insertedtext = '';
			switch(value) {
				case '1':
					insertedtext = 'Uselt';
					break;
				case '2':
					insertedtext = 'inte jättebra';
					break;
				case '3':
					insertedtext = 'Varken eller';
					break;
				case '4':
					insertedtext = 'Ganska bra';
					break;
				case '5':
					insertedtext = 'Föredömligt';
					break;
			}
 
			// Pipe the text to the div
			$('#stjerna').text(insertedtext);		
		});
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: adishardis

Re: get value from star rating and display text 1 year 2 months ago #92539

  • adishardis
  • adishardis's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 58
  • Karma: 0
:woohoo:

You are a Genius!

And congratulations on reaching your fundraiser goal!!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.164 seconds
Donation Image