Have an idea?

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

Free format question with exclusive option

I have a question which asks the total expenditure on a product in the last 12 months. It is a numeric type entry. I need to show one radio button which says No expenditure and it needs to be exclusive and if this is selected the survey terminates.

Can someone help me with a code for the same?

Thanks in advance!
asked Jan 18 by Tarun

1 Answer

0 votes
"Exclusive" is a term usually used to describe a checkbox.  Can you expound on how you want the radio button to behave?

For the survey termination, this skip logic will return true if the radio button is selected:

FreeFormatQ_RadioVar = 1
answered Jan 18 by Zachary Platinum Sawtooth Software, Inc. (63,900 points)
Thanks Zachary for your answer.

For the expenditure question I want that if someone fills in the amount then he/she shouldn't check the radio button(which should be obvious ) and when someone checks the radio button, he/she should be thrown to the end of survey.

Essentially I want the responder to choose only one of the option in the free format question and if he/she selects the second one,  he/she is disqualified.

From what I read, free format is the best type to tackle such cases. Open to try the other type as well
A select question should be able to handle this as well.

It sounds like you may want to use a checkbox rather than a radio button, though.  A radio button, once selected, cannot be unselected unless you click on a different radio button.  If you only have one radio button for "No expenditure," a respondent who accidentally clicks it will not be able to undo their click.

So I would create a check-type select question and give it "No expenditure" as its one response option.  You can then give the select question a skip that skips to your terminate page with this skip logic:

SelectQ_1 = 1


"SelectQ" being the name of the select question, of course.
This definitely helps, but I still have one doubt. So, I have a numeric question along with a checkbox (select) question. Now, a user can enter some number in the numeric box and yet can check the checkbox.  

What I meant from exclusive is that one can only select one of the two things. I know it will be very weird if someone is trying to check both but still I will ideally want to restrict it from happening.
Giving the numeric this code will disable and clear the numeric input when the checkbox is selected:

<script>
$(document).ready(function(){
    if (SSI_GetValue('SelectQ_1')) {
        $('#[% QuestionName() %]').prop('disabled', true);
    }
})

function SSI_CustomGraphicalCheckbox(graphical, input, bln) {
    if (input.name == 'SelectQ_1') {
        if (bln) {
            $('#[% QuestionName() %]').prop('disabled', true).val('');
        }
        else {
            $('#[% QuestionName() %]').prop('disabled', false);
        }
    }
}
</script>


Giving the numeric this custom JavaScript verification will require that either the numeric be answered or the checkbox be selected:

if (!$('#[% QuestionName() %]').val().length && !SSI_GetValue('SelectQ_1')) {
    strErrorMessage = 'Question must be answered or "No expenditure" must be checked.';
}


In both codes, "SelectQ" should be replaced with the name of the select question.
...