- Posts: 22
- Thank you received: 4
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
javascript - get array (numeric) value from previous question
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
10 years 5 months ago - 10 years 5 months ago #100688
by TonisOrmisson
javascript - get array (numeric) value from previous question was created by TonisOrmisson
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:
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?
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:
Code:
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: 10 years 5 months ago by TonisOrmisson.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
10 years 5 months ago #100704
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on 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:
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.
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:
Code:
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: TonisOrmisson
The topic has been locked.
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 22
- Thank you received: 4
10 years 5 months ago #100730
by TonisOrmisson
Replied by TonisOrmisson on topic javascript - get array (numeric) value from previous question
Excellent, thanks!
but how would you check a radio array in a similar case?
but how would you check a radio array in a similar case?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
10 years 5 months ago #100737
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript - get array (numeric) value from previous question
Code:
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 topic has been locked.
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 22
- Thank you received: 4
10 years 5 months ago #100757
by TonisOrmisson
Replied by TonisOrmisson on 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:
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 ... ?
in testing i tried to do also:
Code:
$('#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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
10 years 5 months ago - 10 years 5 months ago #100758
by tpartner
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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic javascript - get array (numeric) value from previous question
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.somehow i can not get the radio array to work
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:
Code:
<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>
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.this interestingly worked but irregularly
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 5 months ago by tpartner.
The following user(s) said Thank You: TonisOrmisson
The topic has been locked.
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 22
- Thank you received: 4
10 years 5 months ago - 10 years 5 months ago #100780
by TonisOrmisson
Replied by TonisOrmisson on topic javascript - get array (numeric) value from previous question
ok, i understand what I got wrong.
Seems to be working now.
Thanks again!
Seems to be working now.
Thanks again!
Last edit: 10 years 5 months ago by TonisOrmisson.
The topic has been locked.