get value from star rating and display text

More
4 years 4 months ago #92437 by adishardis
adishardis created the topic: get value from star rating and display text
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

Please Log in to join the conversation.

More
4 years 4 months ago #92453 by tpartner
tpartner replied the topic: get value from star rating and display text
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.

Please Log in to join the conversation.

More
4 years 4 months ago #92455 by adishardis
adishardis replied the topic: get value from star rating and display text


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
Attachments:

Please Log in to join the conversation.

More
4 years 4 months ago #92536 by tpartner
tpartner replied the topic: get value from star rating and display text
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.
The following user(s) said Thank You: adishardis

Please Log in to join the conversation.

More
4 years 4 months ago #92539 by adishardis
adishardis replied the topic: get value from star rating and display text
:woohoo:

You are a Genius!

And congratulations on reaching your fundraiser goal!!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now