javascript - get array (numeric) value from previous question

More
3 years 6 months ago - 3 years 6 months ago #100688 by t6nnp6nn
t6nnp6nn created the topic: javascript - get array (numeric) value from previous question
Hi

I have a page with multiple questions and a technical hidden question grouping values based on other questions in the bottom of that page. I already regroup based on radio buttons to check which answers are checked like that:
 var q2 = 'sidXgidXqid';
 if ( $('#answer'+q2+'1').attr('checked') == true ){
   // my code here if is checked
 }

now I also need to check answers from a numerical array - I would need to check the values from the first column of each row - whether its checked (checkbox layout) or not. Can anybody help me with the array type?
Last Edit: 3 years 6 months ago by t6nnp6nn.

Please Log in to join the conversation.

More
3 years 6 months ago #100704 by tpartner
tpartner replied the topic: javascript - get array (numeric) value from previous question
Assuming your X-scale sub-question codes are x1, x2, x3...

And the Y-scale codes are y1, y2, y3...

If you want to act on the state of the check-box in row-1, column-1:

var q2 = 'sidXgidXqid';
if ( $('#cbox_'+q2+'y1_x1').is(':checked')){
	// Do something
}


Note, you may want to use .is(:checked) for all of your tests as .attr('checked') has been changed to .prop('checked') in jQuery 1.6 so may not work in new versions of LimeSurvey.

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

Please Log in to join the conversation.

More
3 years 6 months ago #100730 by t6nnp6nn
t6nnp6nn replied the topic: javascript - get array (numeric) value from previous question
Excellent, thanks!

but how would you check a radio array in a similar case?

Please Log in to join the conversation.

More
3 years 6 months ago #100737 by tpartner
tpartner replied the topic: javascript - get array (numeric) value from previous question
var q2 = 'sidXgidXqid';
if ( $('#answer'+q2+'y1-x1').is(':checked')){
	// Do something
}

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
3 years 6 months ago #100757 by t6nnp6nn
t6nnp6nn replied the topic: javascript - get array (numeric) value from previous question
somehow i can not get the radio array to work.

in testing i tried to do also:
$('#answer'+q2+'y1-x1').change(function() {
 
            alert("test");
        });  

this interestingly worked but irregularly. Mostly did not output a message.

i attached the simple example based on the previous post - tried this both with 1.92 and 2.0 and does not seem to work.

Am I doing something wrong or ... ?
Attachments:

Please Log in to join the conversation.

More
3 years 6 months ago - 3 years 6 months ago #100758 by tpartner
tpartner replied the topic: javascript - get array (numeric) value from previous question

somehow i can not get the radio array to work

As far as I can tell, this is working but you are calling it on page load so, as the radio is never checked, nothing happens.

Try this. If using the default template, it will give you an indication of the radio state when you click on the question text of Q1:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
    	var q1 = 'sidXgidXqid';
    	var q1ID = q1.split('X')[2];
		$('#question'+q1ID+' .questiontext').click(function(event) {
			if ( $('#answer'+q1+'y1-x1').is(':checked')) {
				alert('checked');
			}
			else {
				alert('un-checked');
			}
		});
	});
</script>

this interestingly worked but irregularly

The .change() function is only called when you check a radio button, not when you uncheck it by clicking another radio. You will need to put listeners on all of the radios or give them a common class.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 3 years 6 months ago by tpartner.
The following user(s) said Thank You: t6nnp6nn

Please Log in to join the conversation.

More
3 years 6 months ago - 3 years 6 months ago #100780 by t6nnp6nn
t6nnp6nn replied the topic: javascript - get array (numeric) value from previous question
ok, i understand what I got wrong.
Seems to be working now.
Thanks again!
Last Edit: 3 years 6 months ago by t6nnp6nn.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now