Modal window with reference to previous answers

univa2018univa2018 ItalyCommunity Member Qubie ✭

Modal window with reference to previous answers

Hi everybody :) , I'm trying to create a modal window alerting people to control their answers, before going on.

To be precise, my survey questions are (more or less) like these:

  1. How many apples did you buy yesterday? (this is a text entry type of question - single line - with options: force responce and custom validation (value greater or equal than 0))

  2. (this question is displayed only if the answer to the previous question is greater than 0) About those apples, did/will you:

  • make a cake (number of apples)
  • store them (number of apples)
    (This is a side by side question type - with options (custom validation - all entries are Not empty and column options: numerical value)

I would like that when a person answers to question 2 and pushes on "next botton", a modal window opens saying something like:
"Please, before passing to next question, verify that the sum of apples is equal to ANSWER TO question 1."

So the message will be customized for every respondent.

My problem is, how can I write ANSWER TO question 1 in javascript? I am able to create a modal window with a customized text (using the function window.alert), but not to refer to QUESTION 1 ANSWER. Please, can you help me?


Best Answers

  • TomGTomG Raleigh, NC Wizard ✭✭✭✭✭
    Accepted Answer

    First, you pipe the answer to Question 1 into your JS. Something like:

    var q1apples = "${q://QID1/ChoiceTextEntryValue}";

    Then you concatenate the variable to your alert message:

    alert("Please, before passing to next question, verify that the sum of apples is equal to "+q1apples);
  • univa2018univa2018 Italy Qubie ✭
    Accepted Answer

    @Akdashboard @TomG

    I solved my issue, the problem was just to identify the way qualtrics rename my question 1. I got it exporting the CSV of data (4° row of the excel file).

    Just to let you know, this is the code that works:

    var numberofcontracts = "${q://QID25/ChoiceTextEntryValue}"

    window.alert("verify "+numberofcontracts)


    p.s. I'm, a "newcomer", so I apologize if I bothered you with these "little things"... :)


  • AkdashboardAkdashboard South CarolinaCommunity Member Superuser ✭✭✭✭

    @univa2018 - Does it have to be a modal window? I do this type of thing a lot and just use piped text on the next page and ask them to either confirm their answers before proceeding or clicking "back" to change their values.

  • univa2018univa2018 ItalyCommunity Member Qubie ✭

    @Akdashboard @TomG thanks u both for your replies!

    I really would like to have a modal window. My issue is still how to pipe the answer to Question 1 into my JS. I caught @TomG input and this is the code I used (I renamed question 1 "4"):

    { var q1apples = "${q://4/ChoiceTextEntryValue}"
    window.alert("verify "+"q1apples")

    A modal window opens, but jut saying "verify q1apples", so not reporting the value.

    If I write:

    var q1apples = "${q://4/ChoiceTextEntryValue}"
    window.alert("verify "+q1apples)

    The message becomes just "verify".

    I suppose there is something wrong in this piece of code var q1apples = "${q://4/ChoiceTextEntryValue}". May you have any suggestion?

    Thanks a lot!

Sign In to Comment