Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

using the not applicable feature on multiple questions

I wish to use the "Not applicable" question feature on both gender and age questions.

So it will look something like this on the same page …

Age: Numeric
Gender: Select (Male / Female)
Checkbox: Don't know

When the Don't know check box is selected, the age and gender are cleared?

I would also like the text high-lighting of the check box to only high-light the "Don't know" label slightly after the label, rather than the entire survey page.

Thank you.
asked Aug 29, 2018 by Paul Moon Platinum (75,480 points)

1 Answer

0 votes
 
Best answer
Replace the function updateNotApplicableQuestion with this specialized version:

function updateNotApplicableQuestion(baseQuestion, naQuestion, name, bln) {
    $('#[% QuestionName() %]_1').closest('.clickable').css('display', 'inline-block').css('width', 'auto');
    var ageQuestion = $('.question.numeric').attr('id').replace(/_div/, '');
    var sexQuestion = $('.question.select').attr('id').replace(/_div/, '');
    if (bln) {
        $('#' + ageQuestion).val('');
        $('#' + ageQuestion).prop('disabled', true);
        SSI_RadioReset(sexQuestion);
        SSI_DisableGraphicalInput(sexQuestion + '_1');
        SSI_DisableGraphicalInput(sexQuestion + '_2');
    }
    else {
        $('#' + ageQuestion).prop('disabled', false);
        SSI_EnableGraphicalInput(sexQuestion + '_1');
        SSI_EnableGraphicalInput(sexQuestion + '_2');
    }
}


Then replace the verification with this:

var ageQuestionDiv = $('.question.numeric');
var ageQuestion = $(ageQuestionDiv).attr('id').replace(/_div/, '');
var sexQuestionDiv = $('.question.select');
var sexQuestion = $(sexQuestionDiv).attr('id').replace(/_div/, '');

var age = $('#' + ageQuestion).val();
var sex = SSI_GetValue(sexQuestion);
var notApplicable = SSI_GetValue('[% QuestionName() %]_1');

$(ageQuestionDiv).removeClass('error_quest_highlight2');
$('#' + ageQuestion + '_err2').remove();
if (age === '' && !notApplicable) {
    strErrorMessage = 'Question must be answered or "Not Applicable" must be selected.';

    $(ageQuestionDiv).removeClass('error_quest_highlight');
    $('#' + ageQuestion + '_err').remove();
    $(ageQuestionDiv).addClass('error_quest_highlight2');
    $(ageQuestionDiv).prepend('<div id="' + ageQuestion + '_err2" class="question_error_box error_messages"></div>');
    $('#' + ageQuestion + '_err2').append('<div class="question_errors">' + strErrorMessage + '</div>');
}

$(sexQuestionDiv).removeClass('error_quest_highlight2');
$('#' + sexQuestion + '_err2').remove();
if (sex == 0 && !notApplicable) {
    strErrorMessage = 'Question must be answered or "Not Applicable" must be selected.';

    $(sexQuestionDiv).removeClass('error_quest_highlight');
    $('#' + sexQuestion + '_err').remove();
    $(sexQuestionDiv).addClass('error_quest_highlight2');
    $(sexQuestionDiv).prepend('<div id="' + sexQuestion + '_err2" class="question_error_box error_messages"></div>');
    $('#' + sexQuestion + '_err2').append('<div class="question_errors">' + strErrorMessage + '</div>');
}


"DisableGraphicalInputs" from the Community Question Library is still required, of course.
answered Aug 29, 2018 by Zachary Platinum Sawtooth Software, Inc. (124,400 points)
selected Aug 31, 2018 by Paul Moon
Thanks Zachary. Greatly appreciated. I managed to get this working nicely.

I need to use this feature you kindly assisted with in the situation I just mentioned, but I also need it on a survey page where I have parent 1 and parent 2.

Is it also possible to provide the solution for parent 1 and parent 2 (age and gender and each having their own Not applicable checkbox). Also keeping the text high-lighting of the check box label the same too.

Thank you.
Using table-cell instead of inline-block may be what you need.
The table-cell corrected the check box label high-light. Many thanks for the tip.
My final problem is I have 2 parents (age, gender and check box for each parent) on the one survey page.

Parent 1 followed by Parent 2.

I'm trying to make them operate independently.

If I tick the 2nd checkbox (Parent 2), it is clearing the the Parent 1 age and gender?

Any suggestions?
That's just two unmodified Not Applicable questions, right?
No, not really.

I have the following questions ...

Z1a1: parent 1 age (numeric)
Z1b1: parent 1 gender (select - male / female)
Z1c1: parent 1 checkbox (not applicable)

Z1a2: parent 2 age (numeric)
Z1b2: parent 2 gender (select - male / female)
Z1c2: parent 2 checkbox (not applicable)

These are all on the same survey page.

I need the Z1c1 not applicable checkbox to clear Z1a1 and Z1b1.

I need the Z1c2 not applicable checkbox to clear Z1a2 and Z1b2.

The script you provided earlier worked nicely if I only have one parent on the survey page.

Does that makes sense?

Let me know if you want to see a ssi file? Happy to send it through if necessary.

Thanks Zachary.
Oh, I see.  That does invalidate some of the assumptions I had made in my modifications.  Here are a few more changes:

* Replace lines 3-5 of the modified function with this:

var ageQuestion = $('#[% QuestionName() %]_div').prevAll('.question.numeric').eq(0).attr('id').replace(/_div/, '');
var sexQuestion = $('#[% QuestionName() %]_div').prevAll('.question.select').eq(0).attr('id').replace(/_div/, '');
if (SSI_GetValue('[% QuestionName() %]_1')) {


* Similarly, replace lines 1 and 3 of the verification with these two lines:

var ageQuestionDiv = $('#[% QuestionName() %]_div').prevAll('.question.numeric').eq(0);
var sexQuestionDiv = $('#[% QuestionName() %]_div').prevAll('.question.select').eq(0);


* The final change doesn't meet the usual standards I try to hold myself to with the community question library, but shouldn't hurt for a one time change you need.  When you copy-and-paste the Not Applicable question to create a second one, they will both have a few references to the function "updateNotApplicableQuestion" in their footers.  This needs to be changed in such a way that each question is using a unique function name.
Thanks for the latest info Zachary.

I'm still having troubles getting it working? Apologies.

I changed lines 3-4-5 of both checkbox questions.

I also changed removed lines 1+3 in the verifications and replaced them with your 2 new lines of script.

I just sent through the ssi hoping that makes more sense of where I slipped up?
And I was a bit confused by your final comment regarding the final change?
In the second Not Applicable question's footer, replace every "updateNotApplicableQuestion" with "updateNotApplicableQuestion2".  This will keep the second question from writing over the first question's function.
Zachary, that got it working a treat. Very grateful for your timely assistance. Onya mate.
...