Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Enable disable answer option

  • darpao
  • darpao's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 3 months ago #102762 by darpao
Enable disable answer option was created by darpao
How can I disable radio button based on a previous question answer?

For example:

A - Insert a number (1 or 2)

B - Choice one
10 -> enabled if 1 or 2 at A
11 -> enabled if 1 at A
12 -> enabled if 2 at A
13 -> enabled if 1 or 2 at A
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 3 months ago #102776 by tpartner
Replied by tpartner on topic Enable disable answer option
There is no built-in capability to apply conditions or relevance to answers, however, you could create two versions of question "B" and use conditions or relevance to show the appropriate version.

Another approach would be to use JavaScript to filter the answers in question "B" but this would only really work if both questions are on the same page.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • darpao
  • darpao's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 3 months ago #102799 by darpao
Replied by darpao on topic Enable disable answer option
I would like to use Javascript, but I'm not able to find a sample script easy to change..

The first one is not possible because the options are not 2 but more.. so I should use too many versions of second question..

I'm surprised there isn't something like this!!

Anyway, thank you.. I will investigate more..

Actually I use this script, but is not easy to use..
Every time I have to change everything if I copy the survey from a server to another.. but I cannot understand all this calls to questions in LimeSurvey..

For example.
This works for radio button, but for checkbox?!?

Why sometime #question355 is good and other times I need to use #answer364448X11X3551 ?!?

Where I can find all methods that I can apply to a question and its documentation? Like

$("#question354 input").change(function() { ........... });
$("#question355 input").each(function() { ........... });

Or a list of attributes like:
$("#question355 input:radio").attr("checked", false);
$(this).attr("disabled",false);



<script type="text/javascript" charset="utf-8">
function checkGeo() {
var D9 = $("#question354 input:checked").val();
var D10 = [ "#answer364448X11X3551","#answer364448X11X3552","#answer364448X11X3553",
"#answer364448X11X3554","#answer364448X11X3555",
"#answer364448X11X3556","#answer364448X11X3557","#answer364448X11X3558" ];

if (D9 == "9" || D9 == "10") {
for (var i=0; i<=5; i++) {
$(D10).attr("disabled",true);
}

$(D10[7]).attr("disabled",true);

var answer = $("#answer364448X11X3557");
answer.click();
answer.attr("checked", true);

}

else if (D9 != "7" && D9 != "8" && D9 != "11" && D9 != "5") {
$("#answer364448X11X3556").attr("disabled",true);
$("#answer364448X11X3557").attr("disabled",true);
}


}
$(document).ready(function() {
$("#question354 input").change(function() {
// nel caso in cui cambiando la risposta precedente deve essere disabilitato un input già selezionato
$("#question355 input:radio").attr("checked", false);
$("#question355 input").each(function() {
$(this).attr("disabled",false);
});

checkGeo();
});
});
</script>

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose