7 Replies Latest reply on Feb 6, 2014 10:40 AM by philmodjunk

    Display fields based on value of another field

    TylerWray

      Title

      Display fields based on value of another field

      Post

           Hi, everybody. 

           I'm a newbie (like 98% of others here) using FM10 to develop a calendar-based survey tool for use in conducting research (I do public health research). Basically, the idea is that users are presented with a calendar of the last 30 days and they click on each day and answer questions about their behavior on each day. Ultimately, I'll need to have fields for each question within each day. I've been able to construct the calendar so far (using a pretty brutish method), and this basically uses buttons to call up a separate layout for each day that has day-specific fields in it. But, I'd like to be able to only display certain questions based on responses to other questions on the same day. For example, if I had a field storing how many drug use occasions a user had on a given day, I'd like to be able to present a set of questions about each occasion (whether that was 2 or 0). Anybody have any ideas about how I might accomplish this? 

           I've attached my work-in-progress. Please excuse the mess, as I'm uploading it mid-stream! 

        • 1. Re: Display fields based on value of another field
          philmodjunk

               You cannot upload database files to this forum. It sounds like you are using a great many different fields where you should instead have a set of related records. With one record for each question, you can use the response to question #1 to determine what set of follow up question records to bring up next. This allows you to stay with a single layout, but bring up different sets of questions on that layout.

               To start, I suggest that you review this thread on surveys and questionnaires: Need aid on generating a report from a survey layout.

               You may also find this simple calendar demo file of interest: https://www.dropbox.com/s/e8d03xvwe8vtz85/Calendar.fp7

          • 2. Re: Display fields based on value of another field
            TylerWray

                 Thank you very much for your quick reply and for pointing me in the right direction! I had come across that post before, but it didn't make much sense until I studied it a little further. So, I now have three tables, as you suggested: Respondents---<Responses>---Questions . The Respondents table is related to the Responses table via a RespID and the Responses table is related to the questions table via a QuestID. My next question is about how to integrate the number of days issue. Basically, on the first layout, users click on a day "button" on a calendar representing the last 30 days, and answer questions about each day (the "stock" set of questions will be the same, but I'd like them to be able to change based on answers to previous questions about events occurring on the same day) . My question is, should I put a single "day" field (perhaps set by a script when clicking on the associated day button ?) in the questions table that represents the questions for that particular day? Or should I add another table altogether for the days? 

                 Ideally, what I'd like to have is a dataset in which each line has the Respondent ID (repeating), a day (date or a #, e.g., 1, 2, 3), and then several columns representing each question/response. Based on their responses to one of the questions, later items may not be relevant, so these can be just missing (i.e., "."). Like this: 

                 RespID        day        drinks        mjuse        mjusetime     methuse  ...
                 1                     1              5                  0                     .                      0
                 1                     2              0                  0                     .                      0
                 1                     3              1                  1                  12                      0
                  
                  
                 Sorry about the level of detail...just trying to be as clear as possible. Again, I can't thank you enough for your help! 
            • 3. Re: Display fields based on value of another field
              philmodjunk

                   Does the same respondant take the same survey multiple times--each on a different date?

                   In any case, if you need responses to record a date, add a date field for that purpose to the Responses table.

                   It's possible to set up your layouts with a "next" button such that the user is presented with a question or group of questions. When they click "Next", a script can uses the responses given to determine what set of questions to pull up on the layout next.

              • 4. Re: Display fields based on value of another field
                TylerWray

                     Nope, it's just retrospective, so they take it one time on one date, but are answering questions about multiple dates retrospectively (every day over the last 30 days). So I'm basically asking, "Yesterday, did you use certain drugs?" , then "The day before yesterday, did you use certain drugs?" and so on over the last 30 days. 

                     Anything you can point to on what that script presenting different sets of questions might look like? Could this be done on a single layout, or would it require multiple layouts? Thank you!!

                • 5. Re: Display fields based on value of another field
                  philmodjunk

                       "yesterday" can be computed as Get ( CurrentDate ) - 1

                       You could set up a loop where you ask the same basic question, but log dates in the response table progressively farther back in the past until you have queried them about all 30 days.

                  • 6. Re: Display fields based on value of another field
                    TylerWray

                         Yes, that's the way I did it in the calendar set up, and will just use a script to set the day field as the corresponding day as each day "button" is clicked. 

                         But, I was asking about having the questions that are presented within each day change dynamically based on responses to earlier questions about that same day. For example, if I ask "1.) Did you use drug on this day?" I'd ideally like to ask follow-ups about how much of the drug was used and over how long, only for those people who said they did use the drug on that day. So, if their response to "1.) did you use x..." =Yes, then ask the follow-ups, but if it =No, then skip. I thought about accomplishing this by just using multiple layouts, where a "next" button and script are used to take the user to relevant layouts that present follow-up questions (or not) based on earlier responses, but I'm not sure if that's the most efficient way to do this. Is there a way I could just use a single layout that I'm not thinking of? 

                    • 7. Re: Display fields based on value of another field
                      philmodjunk

                           I believe that I have already answered that question. A Next button on your layout can perform a script that uses the answers provided to determine which set of Response records to create, linked to a particular set of question records.