Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: get value from star rating and display text

get value from star rating and display text 1 Jahr 5 Monate her #92437

  • adishardis
  • adishardiss Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: get value from star rating and display text 1 Jahr 5 Monate her #92453

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 748
  • Karma: 341
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: get value from star rating and display text 1 Jahr 5 Monate her #92455

  • adishardis
  • adishardiss Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: get value from star rating and display text 1 Jahr 5 Monate her #92536

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 748
  • Karma: 341
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: adishardis

Re: get value from star rating and display text 1 Jahr 5 Monate her #92539

  • adishardis
  • adishardiss Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 58
  • Karma: 0
:woohoo:

You are a Genius!

And congratulations on reaching your fundraiser goal!!
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.214 Sekunden
Donation Image