Filling hidden question based on number question answer

More
2 years 10 months ago #116470 by rchudek
rchudek created the topic: Filling hidden question based on number question answer
Hi.
I'm trying to fill a hidden radioButton question with an answer based on value from answered number question.
Tried to do so by using some JS Script, but there is no value written to my hidden question.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
           var age=parseInt('{INSERTANS:228958X5X16}');
 
           if(age < 25)
              $('#answer228958X5X48').val("1");
           else if(age >= 25 && age <= 34)
              $('#answer228958X5X48').val("2");
           else if(age >= 35 && age <= 44)
              $('#answer228958X5X48').val(3);
           else if(age >= 45 && age <= 54)
              $('#answer228958X5X48').val(4);
           else if(age > 54)
              $('#answer228958X5X48').val(5);
 
           // Hide question
           $("#question48").hide();
 
          //Go to next question
          $("#defaultbtn").click();
 
	});
 
</script>

Can you please tell me where and what I'm doing wrong here?

Please Log in to join the conversation.

More
2 years 10 months ago #116471 by tpartner
tpartner replied the topic: Filling hidden question based on number question answer
Assuming the radio question (ID 48?) has answer codes "A1, A2, A3, A4, A5", then try this:

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
           var age=parseInt('{INSERTANS:228958X5X16}');
 
           if(age < 25)
              $('#answer228958X5X48A1').trigger('click');
           else if(age >= 25 && age <= 34)
              $('#answer228958X5X48A2').trigger('click');
           else if(age >= 35 && age <= 44)
              $('#answer228958X5X48A3').trigger('click');
           else if(age >= 45 && age <= 54)
              $('#answer228958X5X48A4').trigger('click');
           else if(age > 54)
              $('#answer228958X5X48A5').trigger('click');
 
           // Hide question
           $("#question48").hide();
 
          //Go to next question
          $("#defaultbtn").click();
 
	});
 
</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.

More
2 years 10 months ago #116472 by rchudek
rchudek replied the topic: Filling hidden question based on number question answer
Thank you very much! That did the work perfectly!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!