The LimeSurvey Fund-Raiser 2012 is complete. Thank you for donating a total of 25,000 USD!     List of donors »

Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: get value from star rating and display text

get value from star rating and display text 3 months 1 week ago #92437

  • adishardis
  • adishardis's Avatar
  • OFFLINE
  • Silver Donor
  • Posts: 57
  • 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 3 months 1 week ago #92453

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2868
  • Thank you received: 428
  • Karma: 246
Adam, where do you want to display the text? Can you provide a mockup?
Cheers,
Tony

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 3 months 1 week ago #92455

  • adishardis
  • adishardis's Avatar
  • OFFLINE
  • Silver Donor
  • Posts: 57
  • 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 3 months 1 week ago #92536

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2868
  • Thank you received: 428
  • Karma: 246
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

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 3 months 1 week ago #92539

  • adishardis
  • adishardis's Avatar
  • OFFLINE
  • Silver Donor
  • Posts: 57
  • Karma: 0
:woohoo:

You are a Genius!

And congratulations on reaching your fundraiser goal!!
The administrator has disabled public write access.
  • Page:
  • 1
Moderators: DenisChenu, ITEd
Time to create page: 0.244 seconds
Donation Image