- Posts: 10613
- Thank you received: 3691
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Disable specific boxes (=answer options) in a array question (numbers)
- tpartner
- Away
- LimeSurvey Community Team
Less
More
9 years 4 months ago - 9 years 4 months ago #113905
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 Disable specific boxes (=answer options) in a array question (numbers)
If there is no filtering in the question and if it is the only array-numbers on the page and you are using the default template, you can try this:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Some classes and attributes $('.array-multi-flexi table.question thead tr > *').each(function(i){ $(this).attr('data-column', i); }); $('.array-multi-flexi table.question tbody tr').each(function(i){ $('> *', this).each(function(i){ $(this).attr('data-column', i); }); }); // Hide unnecessary selects $('.array-multi-flexi table.question tbody tr').each(function(i){ $('select:visible:lt('+i+')', this).hide(); $('select:visible:eq(0)', this).hide(); }); // Remove unecessary rows and columns $('.array-multi-flexi table.question tbody tr:last').hide(); $('.array-multi-flexi th[data-column="1"], td[data-column="1"]').hide(); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 4 months ago by tpartner.
The following user(s) said Thank You: daveintausend
The topic has been locked.
- daveintausend
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
9 years 4 months ago #113910
by daveintausend
Replied by daveintausend on topic Disable specific boxes (=answer options) in a array question (numbers)
Thanks a lot Tony, with the Default template this indeed seems to work aswell.
The topic has been locked.
- bdeprez
- Offline
- Senior Member
Less
More
- Posts: 53
- Thank you received: 5
6 years 9 months ago #155061
by bdeprez
Replied by bdeprez on topic Disable specific boxes (=answer options) in a array question (numbers)
Hi all,
This is a pretty old topic and I think it may no longer work the same... Or I'm doing something wrong (this is the most probable of the both).
I'm trying to hide a radio button in an array
The button I'm trying to hide is the following in my page source:
This is the script I am using:
What am I doing wrong? I tried the 'alert' test just to be sure that my javascript is on and that worked...
Thanks in advance for your help!
This is a pretty old topic and I think it may no longer work the same... Or I'm doing something wrong (this is the most probable of the both).
I'm trying to hide a radio button in an array
The button I'm trying to hide is the following in my page source:
Code:
<!-- answer_td --> <td class="answer-cell-3 answer_cell_A1 answer-item radio-item text-center radio"> <input class="radio" type="radio" name="783318X281X2223SQ001" value="A1" id="answer783318X281X2223SQ001-A1" onclick="checkconditions(this.value, this.name, this.type)" aria-labelledby="label-answer783318X281X2223SQ001-A1" /> <label for="answer783318X281X2223SQ001-A1" ></label> <!-- The label text is provided inside a div, so final user can add paragraph, div, or whatever he wants in the subquestion text This field is related to the input thanks to attribute aria-labelledby --> <div class="visible-xs-block label-text" id="label-answer783318X281X2223SQ001-A1"> Very Good </div> </td> <!-- end of answer_td -->
This is the script I am using:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('input.radio[name="783318X281X2223SQ001-A1"]').attr('hidden', 'hidden'); }); </script>
What am I doing wrong? I tried the 'alert' test just to be sure that my javascript is on and that worked...
Thanks in advance for your help!
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10613
- Thank you received: 3691
6 years 9 months ago #155070
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 Disable specific boxes (=answer options) in a array question (numbers)
To avoid manipulating multiple radios, I would use the element ID as a selector. Also, to hide any pseudo-elements, I would hide or remove all of the radio's siblings.
Or:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#answer783318X281X2223SQ001-A1').closest('.answer-item').find('*').hide(); }); </script>
Or:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#answer783318X281X2223SQ001-A1').closest('.answer-item').find('*').remove(); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- bdeprez
- Offline
- Senior Member
Less
More
- Posts: 53
- Thank you received: 5
6 years 9 months ago #155072
by bdeprez
Replied by bdeprez on topic Disable specific boxes (=answer options) in a array question (numbers)
Hi tpartner!
thank you very much for your response - I have a quick follow up question...
I had to change my array to an 'Array (numbers)' as I had to allow for multiple boxes to be checked for the same subquestion - that makes that my previous question no longer fits the purpose...
So, now I have 3 questions (X-axis) and 2 answers (Y-axis) which all can be selected with a checkbox.
This is the first "answer row":
How would I go and hide the second answer option?
Thank you very much!!!
thank you very much for your response - I have a quick follow up question...
I had to change my array to an 'Array (numbers)' as I had to allow for multiple boxes to be checked for the same subquestion - that makes that my previous question no longer fits the purpose...
So, now I have 3 questions (X-axis) and 2 answers (Y-axis) which all can be selected with a checkbox.
This is the first "answer row":
Code:
<!-- answer_row --> <tr id="javatbd783318X281X2231SQ001" class=" well subquestion-list questions-list array2 "> <th class="answertext col-xs-12 col-sm-6"> Voice <input type="hidden" name="java783318X281X2231SQ001" id="java783318X281X2231SQ001" value="" /> </th> <!-- answer_td_checkboxes --> <td class="answer-cell-6 answer_cell_SQ001 question-item answer-item checkbox-item checkbox-item checkbox text-center"> <input type="hidden" name="java783318X281X2231SQ001_SQ001" id="java783318X281X2231SQ001_SQ001" value="" /> <input type="hidden" name="783318X281X2231SQ001_SQ001" id="answer783318X281X2231SQ001_SQ001" value="" /> <input type="checkbox" class="checkbox " name="cbox_783318X281X2231SQ001_SQ001" id="cbox_783318X281X2231SQ001_SQ001" onclick=" cancelBubbleThis(event); aelt=document.getElementById('answer783318X281X2231SQ001_SQ001'); jelt=document.getElementById('java783318X281X2231SQ001_SQ001'); if(this.checked) { aelt.value=1; jelt.value=1; fixnum_checkconditions(1,'783318X281X2231SQ001_SQ001',aelt.type); } else { aelt.value=''; jelt.value=''; fixnum_checkconditions('','783318X281X2231SQ001_SQ001',aelt.type); } return true;" onchange="checkconditions(this.value, this.name, this.type)" aria-labelledby="label-cbox_783318X281X2231SQ001_SQ001" /> <label for="cbox_783318X281X2231SQ001_SQ001"></label> <!-- The label text is provided inside a div, so final user can add paragraph, div, or whatever he wants in the subquestion text This field is related to the input thanks to attribute aria-labelledby --> <div class="visible-xs-block label-text" id="label-cbox_783318X281X2231SQ001_SQ001"> Dealer to Dealer (D2D) </div> </td> <!-- end of answer_td_checkboxes --> <!-- answer_td_checkboxes --> <td class="answer-cell-6 answer_cell_SQ002 question-item answer-item checkbox-item checkbox-item checkbox text-center"> <input type="hidden" name="java783318X281X2231SQ001_SQ002" id="java783318X281X2231SQ001_SQ002" value="" /> <input type="hidden" name="783318X281X2231SQ001_SQ002" id="answer783318X281X2231SQ001_SQ002" value="" /> <input type="checkbox" class="checkbox " name="cbox_783318X281X2231SQ001_SQ002" id="cbox_783318X281X2231SQ001_SQ002" onclick=" cancelBubbleThis(event); aelt=document.getElementById('answer783318X281X2231SQ001_SQ002'); jelt=document.getElementById('java783318X281X2231SQ001_SQ002'); if(this.checked) { aelt.value=1; jelt.value=1; fixnum_checkconditions(1,'783318X281X2231SQ001_SQ002',aelt.type); } else { aelt.value=''; jelt.value=''; fixnum_checkconditions('','783318X281X2231SQ001_SQ002',aelt.type); } return true;" onchange="checkconditions(this.value, this.name, this.type)" aria-labelledby="label-cbox_783318X281X2231SQ001_SQ002" /> <label for="cbox_783318X281X2231SQ001_SQ002"></label> <!-- The label text is provided inside a div, so final user can add paragraph, div, or whatever he wants in the subquestion text This field is related to the input thanks to attribute aria-labelledby --> <div class="visible-xs-block label-text" id="label-cbox_783318X281X2231SQ001_SQ002"> Dealer to Client (D2C) </div> </td> <!-- end of answer_td_checkboxes --> <!-- right --> </tr> <!-- end of answer_row -->
How would I go and hide the second answer option?
Thank you very much!!!
The topic has been locked.
- bdeprez
- Offline
- Senior Member
Less
More
- Posts: 53
- Thank you received: 5
6 years 9 months ago #155073
by bdeprez
Replied by bdeprez on topic Disable specific boxes (=answer options) in a array question (numbers)
Never mind - I just tried out your code above and replaced it with the name of the checkbox and it did the trick!
Thanks again!
Thanks again!
The topic has been locked.
- mcovents
- Offline
- Senior Member
Less
More
- Posts: 43
- Thank you received: 0
5 years 2 weeks ago #181228
by mcovents
Replied by mcovents on topic Disable specific boxes (=answer options) in a array question (numbers)
I also want to hide a radio button for some subquestions in an array question but it doesn't seem to work.
It does work for checkboxes in an array(numbers) question but I need an array question with radio buttons.
I'm using Limesurvey version 3.15
This is the code that I'm trying to use:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('input[name="695528X43X1563SQ001_SQ001"]').attr('disabled', 'disabled');
$('input[name="695528X43X1563SQ002_SQ002"]').attr('hidden', 'hidden');
});
</script>
It does work for checkboxes in an array(numbers) question but I need an array question with radio buttons.
I'm using Limesurvey version 3.15
This is the code that I'm trying to use:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('input[name="695528X43X1563SQ001_SQ001"]').attr('disabled', 'disabled');
$('input[name="695528X43X1563SQ002_SQ002"]').attr('hidden', 'hidden');
});
</script>
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10613
- Thank you received: 3691
5 years 2 weeks ago #181234
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 Disable specific boxes (=answer options) in a array question (numbers)
Can you attach a small sample survey export (.lss) file containing only the relevant question and describe which radio(s) you are trying to disable?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- mcovents
- Offline
- Senior Member
Less
More
- Posts: 43
- Thank you received: 0
5 years 2 weeks ago #181235
by mcovents
Replied by mcovents on topic Disable specific boxes (=answer options) in a array question (numbers)
Dear Tony,
In the attached file we have put two questions.
The first one is what we really want: an array with radio buttons however in the first and second row we would like to hide the 3th and 4th option.
After trying several versions, the best we could get is presented in the second question, where we were able to disable (but not hide) check boxes.
However for our current project we need radio buttons, and not check boxes....
Best regards,
Marc
In the attached file we have put two questions.
The first one is what we really want: an array with radio buttons however in the first and second row we would like to hide the 3th and 4th option.
After trying several versions, the best we could get is presented in the second question, where we were able to disable (but not hide) check boxes.
However for our current project we need radio buttons, and not check boxes....
Best regards,
Marc
Attachments:
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10613
- Thank you received: 3691
5 years 2 weeks ago #181236
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 Disable specific boxes (=answer options) in a array question (numbers)
It's not a good idea to use the same question codes for the x and y axes - it leads to confusion when trying to identify elements. For this example, I have recoded the Q1 answers (x-axis) to A1-A4.
Rather than hiding the elements, you should remove them so they cannot be selected via the keyboard.
In your example, add something like this to the question source:
Sample survey attached:
Rather than hiding the elements, you should remove them so they cannot be selected via the keyboard.
In your example, add something like this to the question source:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Remove row 1, answer "A3" $('#question{QID} tr.answers-list:eq(0) input:radio[value="A3"]').nextAll('label').remove(); $('#question{QID} tr.answers-list:eq(0) input:radio[value="A3"]').remove(); // Remove row 1, answer "A4" $('#question{QID} tr.answers-list:eq(0) input:radio[value="A4"]').nextAll('label').remove(); $('#question{QID} tr.answers-list:eq(0) input:radio[value="A4"]').remove(); // Remove row 2, answer "A3" $('#question{QID} tr.answers-list:eq(1) input:radio[value="A3"]').nextAll('label').remove(); $('#question{QID} tr.answers-list:eq(1) input:radio[value="A3"]').remove(); // Remove row 2, answer "A4" $('#question{QID} tr.answers-list:eq(1) input:radio[value="A4"]').nextAll('label').remove(); $('#question{QID} tr.answers-list:eq(1) input:radio[value="A4"]').remove(); }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- mcovents
- Offline
- Senior Member
Less
More
- Posts: 43
- Thank you received: 0
5 years 2 weeks ago #181239
by mcovents
Replied by mcovents on topic Disable specific boxes (=answer options) in a array question (numbers)
Super!
This is what we were looking for.
Best regards,
Marc
This is what we were looking for.
Best regards,
Marc
The topic has been locked.
- mcovents
- Offline
- Senior Member
Less
More
- Posts: 43
- Thank you received: 0
5 years 2 weeks ago #181247
by mcovents
Replied by mcovents on topic Disable specific boxes (=answer options) in a array question (numbers)
Dear Tony,
Can we ask you another question in the same area?
Do you also have a suggestion how we could remove some input fields in text (and number) arrays in the 3.15 version?
We used this type of question in another survey in which teachers have to indicate when they are available and when not for 6 days of the week (monday-saturday) for three time slots (morning, afternoon and evening).
More specific we used a text array question (example 1 in the attached file), which we further elaborated with a javascript so that they could select their responses from drop down lists (example 2 in attach).
However some of the options are redundant as our school is closed on friday evening as well as on saturday afternoon and evening.
the example is a bit comparable to the example given on
manual.limesurvey.org/Workarounds:_Manip...ation_LS_Version_3.x :
Disable or hide selected fields in a matrix question
We were able to disable options in example 1, but not to remove them. However when we put the extra javascript on it (example 2), also the disable did not work anymore....
As we did not find a sollution to remove those fields we added an extra option "there is no class". It would however be more userfriendly if we could remove the unnecessary fields...
Suggestions would be very welcome, as well for the less complex text (example1) and numer arrays as for the more complex one (example 2)...
Thanks in advance
Marc.
Can we ask you another question in the same area?
Do you also have a suggestion how we could remove some input fields in text (and number) arrays in the 3.15 version?
We used this type of question in another survey in which teachers have to indicate when they are available and when not for 6 days of the week (monday-saturday) for three time slots (morning, afternoon and evening).
More specific we used a text array question (example 1 in the attached file), which we further elaborated with a javascript so that they could select their responses from drop down lists (example 2 in attach).
However some of the options are redundant as our school is closed on friday evening as well as on saturday afternoon and evening.
the example is a bit comparable to the example given on
manual.limesurvey.org/Workarounds:_Manip...ation_LS_Version_3.x :
Disable or hide selected fields in a matrix question
We were able to disable options in example 1, but not to remove them. However when we put the extra javascript on it (example 2), also the disable did not work anymore....
As we did not find a sollution to remove those fields we added an extra option "there is no class". It would however be more userfriendly if we could remove the unnecessary fields...
Suggestions would be very welcome, as well for the less complex text (example1) and numer arrays as for the more complex one (example 2)...
Thanks in advance
Marc.
Attachments:
The topic has been locked.