Math operation for calculating the maximum value | XM Community
Skip to main content
Solved

Math operation for calculating the maximum value


Forum|alt.badge.img+1
I have three questions that ask about respondents' travel distance. And I want to redirect a respondent at the end of a survey to different URLs, based on the longest distance reported, like: * If the longest distance among three is less than 5: redirect to "google.com" * If the longest distance among three is between 5 and 10: redirect to "youtube.com" * If the longest distance among three is over than 10: redirect to "amazon.com" So, for example, if a respondent answered 5, 3, 8 miles for each question, I'd like to redirect this respondent to "youtube.com" because the longest one is "8." Is it possible to do this by using math operations or javascript? I tried to use Qualtrics' math operation, but it seems that there is no operation for like this: $e{max(q://QID16ChoiceTextEntryValue, q://QID17ChoiceTextEntryValue, q://QID18ChoiceTextEntryValue)} Any suggestions will be welcome. Thank you.

Best answer by TomG

JS: ``` var max = Math.max(parseInt("${q://QID16ChoiceTextEntryValue"), parseInt("${q://QID17ChoiceTextEntryValue}"), parseInt("${q://QID18ChoiceTextEntryValue)}")); Qualtrics.SurveyEngine.setEmbeddedData("max", max); ``` In survey flow branch: If max > X etc.
View original

5 replies

PeeyushBansal
Level 6 ●●●●●●
Forum|alt.badge.img+39
  • Level 6 ●●●●●●
  • 1144 replies
  • March 1, 2019
you can use simple if conditions or java script to punch max value from 3 numbers.

  • 0 replies
  • March 1, 2019
Hello @jhwang , You can use Redirect to URL option to redirect the respondent

Forum|alt.badge.img+1
  • Author
  • 22 replies
  • March 1, 2019
Hello @Shashi , I know how to use Redirect to URL option. But I want to know how to detect the maximum value of reported answers and then redirect the respondent based on the value.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5932 replies
  • Answer
  • March 1, 2019
JS: ``` var max = Math.max(parseInt("${q://QID16ChoiceTextEntryValue"), parseInt("${q://QID17ChoiceTextEntryValue}"), parseInt("${q://QID18ChoiceTextEntryValue)}")); Qualtrics.SurveyEngine.setEmbeddedData("max", max); ``` In survey flow branch: If max > X etc.

Forum|alt.badge.img+1
  • Author
  • 22 replies
  • March 1, 2019
Thank you very much, @TomG! This is what I exactly wanted to do.

Leave a Reply