Answered

How do I loop through a question multiple times?


For example, on question 3 the user can enter the number of times they have eaten at a restaurant. For each time, they fill in a series of questions about the experience (did they have a drink? if so, what? did they order an appetizer, etc). 

 

I want to have the same set of questions that repeat 1 to n times where n is the answer to question 3. 

 

I DO NOT want to have to duplicate the question for every possible value of n. It could be a large number and frustrating to the user if they can’t include every experience. 

 

Thanks!

icon

Best answer by john.desborough 29 March 2023, 20:16

View original

10 replies

Userlevel 7
Badge +5

Hi @jbakes Happy Wednesday! I hope you’re having a great week so far. 

I’m afraid that we don’t have a feature that would allow you to loop through the same question multiple times, so you will need to duplicate the question. 

I’d suggest taking a look at some similar posts on this like the one below: 

 

Userlevel 7
Badge +6

@jbakes @Liz - one possible solution MIGHT be to do something like this: 

  • create a variable into which you will put the answer to q3 - ie the number of times 
  • redirect the user to a second form where you will collect the details about each of the times:
    • pass the variable to the second form as a hidden variable in the redirect url
    • create a hidden variable inside the second form to catch the passed variable (the count) 
    • add logic rules at the end of the question that go something like this
      • if n gt 0 subtract 1 from n (where n is the name of the variable you passed) 
      • if n gt 0 go to redirect ending that takes you back to the same (second) form - this variable would be passed as a hidden variable in the url again
      • if n = 0 redirect to another typeform (ie a third form in the series that you might have in place if there are more questions to ask, etc) 

that should keep the person looping in the same redirected second form until their count has been reduced to 0 and then you send them somewhere else … 

 

just a thought

 

des

@Liz I tried just duplicating the question groups multiple times (not ideal because I had to re-work the content of my survey), then I get this error when I try to apply logic to it: “Logic map not available! Too many logic rules to visualize”. I’m just trying to add logic where at the end of the group if the user has another thing to log it takes them to the next question group.

Userlevel 7
Badge +5

Hi @jbakes The error is stating that there are too many logic jumps on the form and you may need to remove some in order to continue adding others. This is to ensure the form runs smoothly instead of possibly taking a long time to load because of the jumps. Are there any jumps that could be removed? 

Userlevel 2
Badge +1

It’s disappointing that this is still a limitation. Ideally one would also be able to govern what’s shown in the loop with an earlier question - for example, which of these products do you buy, then for each one bought, where did you buy it and how much did you spend. Anything more than a few items and it becomes extremely tedious, then one hits the jump limitations. It’s a very basic survey technique that they really need to implement if they want to keep up with the likes of Survey Monkey.

Userlevel 7
Badge +5

Hi @ChrisAtCentral Oh yeah, I totally agree. As much as I love building Typeforms, I’m lazy and don’t like duplicating questions, either. I’ve asked our product team if there are any upcoming plans for this. 

Userlevel 7
Badge +5

Hi again, @ChrisAtCentral The product team let me know this isn’t a feature they plan on adding, but if that changes, I’ll post so here. 

Good day,

 

I’m trying to create a form where one of the questions is “How many devices do you have?”. Depending on the answer, I need to autogenerate the same number of question groups for each device.

 

Example: the user enters 27. I need an automatic self incremental loop that asks the same 3 questions (1. Make? 2. Model 3. Internet Connected?) for Device 1, Device2 ….Device 27.

 

I cannot manually create these loops because the number might be 127 or 887. And I cannot create a question “Add new device?” and connected it to the beginning of an existing loop, because answers will be overwritten.

 

Thanks in advance.

Userlevel 7
Badge +5

Hi @Allinfra I’ve moved your post here where we have an existing conversation about this. 😀

Userlevel 7
Badge +6

 @Allinfra - while Typeform does not have the ability to generate the number of question groups dynamically, you could try this - i have done a flavour of this for a client in a similar scenario:

  • create a separate typeform for the questions for the device
  • you can pass the number of devices as a hidden variable into the second form like this:
    • create the hidden field in the second form - call it v_count, for example
    • logic rule in first form that asks how many devices
      • if q3 (my example) is greater than 0 add q3 to v_count (also created in first typeform) 
    • pass the value of the v_count from the first form to the second form as part of the url string (created when you create the second typeform, the hidden variable and share the link) 
  • in the second form, you start the logic rules with something like this:
    • if v_count greater than 0 then go to first question 
    • at the end of the questions for this device, you can use a logic rule to do the following
      • subtract 1 from v_count
      • if v_count is greater than 0 redirect the user on submission of the form back to the same url for the second form - including the new v_count number as the value in the url… ie if  you had passed in 27 to start, v_count would now be 26 and since it is greater than 0 you can send the user to the form … it will process again and reduce the counter to 25 on the next pass. 

alternatively you break it into the two forms and at the end of the second form you ask them do they want to add another device yes or now - if they choose no, you kick them out to an ending or another form. .if they choose yes, you route them back to the same url.. be sure to add any hidden fields to the strings that will keep the unique identifier consistent (ie email address, etc.) 

 

might work for you.. 

des

Reply