Language Switch as List (radio)

  • TwentyTwo
  • TwentyTwo's Avatar Topic Author
  • Visitor
  • Visitor
4 years 1 month ago #96332 by TwentyTwo
TwentyTwo created the topic: Language Switch as List (radio)
Hi,

I would like to use the Language Switch question but not as drop down but just as a radio list.

Therefore I create a new radio list question with (in this case) 3 answers for the specific languages that I have in my Survey.

In the code itself I try to manipulate this with JS:
<script type="text/javascript" charset="utf-8" >
$(document).ready(function() {
 
if ($( '#answer68224X108X852A1' ).attr('checked') == true ){
 document.getElementById('lang').value="nl-informal"; 
};
if ($( '#answer68224X108X852A2' ).attr('checked') == true ){
 document.getElementById('lang').value="de"; 
};
if ($( '#answer68224X108X852A3' ).attr('checked') == true ){
 document.getElementById('lang').value="nl"; 
};
 
 
};
</script>

This is not working as I would expect, any idea how to change this?

Please Log in to join the conversation.

More
4 years 1 month ago #96344 by tpartner
tpartner replied the topic: Language Switch as List (radio)
Try something like:
<script type="text/javascript" charset="utf-8" >
	$(document).ready(function() {
 
		$( '#answer68224X108X852A1' ).click(function() {
			document.getElementById('lang').value="nl-informal"; 
		});
		$( '#answer68224X108X852A2' ).click(function() {
			document.getElementById('lang').value="de"; 
		});
		$( '#answer68224X108X852A3' ).click(function() {
			document.getElementById('lang').value="nl"; 
		});
	};
</script>

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.

  • TwentyTwo
  • TwentyTwo's Avatar Topic Author
  • Visitor
  • Visitor
4 years 1 month ago #96347 by TwentyTwo
TwentyTwo replied the topic: Language Switch as List (radio)
Thanks Tony,

See your point, however not working - I think I still have something wrong on the getElement - it should be something like setting something right?
Not sure if you can see it quickly?

I will play around a bit more later as well and post the solution when founded.

Please Log in to join the conversation.

More
4 years 1 month ago #96349 by tpartner
tpartner replied the topic: Language Switch as List (radio)
Ah, it seems that the <input id="lang"> element is only present in the language-switch question so you will need to add it to your question source.

Also, I had a small syntax error in my script.

So, add this to the source of the question in all languages:
<input id="lang" type="hidden" value="" name="lang">
<script type="text/javascript" charset="utf-8" >
	$(document).ready(function() {
 
		$( '#answer68224X108X852A1' ).click(function() {
			document.getElementById('lang').value="nl-informal"; 
		});
		$( '#answer68224X108X852A2' ).click(function() {
			document.getElementById('lang').value="de"; 
		});
		$( '#answer68224X108X852A3' ).click(function() {
			document.getElementById('lang').value="nl"; 
		});
	});
</script>

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.

Start now!

Just create your account and start using Limesurvey today.

Register now