Have an idea?

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

How to code: allow only one response in a free forum question type


I have a free forum question that asks respondents to answer how often they replace something. They are given the option of answering that in 'hours' or 'years'. The answers can be provided by free entry numerical boxes.

I am looking for two codes: 1) mandates that the respondents answers one of the two and 2) once they answer one of them, they are no longer able to answer the other.

Hopefully this is enough info!
asked Apr 8, 2020 by Brady

1 Answer

0 votes
Set both variables to not require a response, then give the free format question this custom JavaScript verification:

var answered = 0;
$('#[% QuestionName() %]_var1, #[% QuestionName() %]_var2').each(function(){
    if ($(this).val().trim()) {

switch (answered) {
    case 0:
        strErrorMessage = 'Response is required.';
    case 2:
        strErrorMessage = 'Cannot respond to both inputs.';

"var1" and "var2" must be replaced with the names of the free format variables, respectively.  Naturally, those two error message texts can be replaced with whatever error you want shown to respondents.
answered Apr 8, 2020 by Zachary Platinum Sawtooth Software, Inc. (216,575 points)