Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: javascript - get array (numeric) value from previous question

javascript - get array (numeric) value from previous question 2 years 11 months ago #100688

  • t6nnp6nn
  • t6nnp6nn's Avatar
  • Offline
  • Junior Lime
  • Posts: 25
  • Thank you received: 1
  • Karma: 0
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: 2 years 11 months ago by t6nnp6nn.
The administrator has disabled public write access.

javascript - get array (numeric) value from previous question 2 years 11 months ago #100704

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6323
  • Thank you received: 1407
  • Karma: 547
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 administrator has disabled public write access.
The following user(s) said Thank You: t6nnp6nn

javascript - get array (numeric) value from previous question 2 years 11 months ago #100730

  • t6nnp6nn
  • t6nnp6nn's Avatar
  • Offline
  • Junior Lime
  • Posts: 25
  • Thank you received: 1
  • Karma: 0
Excellent, thanks!

but how would you check a radio array in a similar case?
The administrator has disabled public write access.

javascript - get array (numeric) value from previous question 2 years 11 months ago #100737

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6323
  • Thank you received: 1407
  • Karma: 547
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.
The administrator has disabled public write access.

javascript - get array (numeric) value from previous question 2 years 11 months ago #100757

  • t6nnp6nn
  • t6nnp6nn's Avatar
  • Offline
  • Junior Lime
  • Posts: 25
  • Thank you received: 1
  • Karma: 0
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:
The administrator has disabled public write access.

javascript - get array (numeric) value from previous question 2 years 11 months ago #100758

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6323
  • Thank you received: 1407
  • Karma: 547
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: 2 years 11 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: t6nnp6nn

javascript - get array (numeric) value from previous question 2 years 11 months ago #100780

  • t6nnp6nn
  • t6nnp6nn's Avatar
  • Offline
  • Junior Lime
  • Posts: 25
  • Thank you received: 1
  • Karma: 0
ok, i understand what I got wrong.
Seems to be working now.
Thanks again!
Last Edit: 2 years 11 months ago by t6nnp6nn.
The administrator has disabled public write access.
Time to create page: 0.230 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form