Wednesday, July 17, 2013

Google Form: Dynamically creating drop down list from a named range in Google Spreadsheet


I love using Google Form for collecting data and surveys. At times, I wish a feature, where inputs for Drop Down List, Checkbox or Multiple choice could be feed from excel sheet. This will help us when form itself is dependent on values from some other source.


We can achieve it with a simple google script. The script is executed from spreadsheet. It updates the Google form with a trigger set 'on change' on spreadsheet.

In below script, I take an existing google form and modify one of the drop down item in it. The values for this drop down item is fed from a named range in current active sheet.



30 comments:

  1. Glad to see you back to technical blogging. Best of luck...

    ReplyDelete
  2. Nitin - Thank you for this post. I have been wondering about this for some time. I have successfully implemented your script for one name range and one drop down list question. However I have run into trouble when I try to do Check Boxes and run into an error that it cannot find the .ascheckbox in object. I am not well versed in programming.... I am not sure if I have to choose a whole new set of variable names for each question that I wish to dynamically populate ? Please advise.

    ReplyDelete
  3. Sorry @PropertyTech I didn't understand your problem. Possibly, it might be due to mismatch in kind of item you are manipulating. Probably, you are trying to modify an item which is not really a check box. Can you please share your form / script with me tachniki@gmail.com?

    ReplyDelete
  4. thats amazing, exactly what im looking for.

    thanks man

    ReplyDelete
    Replies
    1. Thanks Mohammed for response. I hope it helped. :)

      Delete
  5. Hey Nitin, I'm facing a problem while executing your code in my form. at time of saving the script an error ""Syntax error. (line 64, file "Code")"" is showing up. I think this is because of newer version of Google services. Can you please suggest any new method for the same.

    ReplyDelete
    Replies
    1. Line 64 is last line. Is it due to some missing parenthesis.

      Delete
    2. Hi Nitin
      Hope you can assist as this is exactly what I am looking for. Like Kapil I am also getting the Syntax error (line 64, file "Code") however as am not fluent in code am unable to pinpoint where I am missing parenthesis. I have tried many and asked around but no luck
      Would it be possible for me to share with you to you to have a look at for me? It would be much appreciated
      Thanks

      Delete
    3. Hi Lane,
      Are you exactly using same code? Can you please drop me a mail at tachniki @ Gmail and share whatever you have written? I will look at it.

      Delete
    4. There was a bug in above code. Line number 60 has a parenthesis that was causing issue. Updated it.

      Delete
  6. please can you help me ? I need help to update the google form when user select answer of question 1 the options of question 2 will change "because the options of question 2 dependent on answer of question 1 "
    for example
    Q1-buildings:
    - building 1
    - building 2
    Q2- rooms:
    if the user select building 1
    the options will be
    room 202
    room 205
    if the user select building 2
    the options will be
    room 304
    room 309
    do you know how can do this ?

    ReplyDelete
    Replies
    1. Hi Salha,

      One simple way to do this will be using condition in google form and taking user to different page. But I don't think that is most elegant solution as the values will be stored in different columns.

      I have not got much time to find a programmatic solution for this. Let me see if I can do some research in next weekend. :)

      Delete
    2. thanks, Nitin Jain
      I used this way, but this way take more time from users.
      :)

      Delete
    3. I agree it takes more time. I hope we had better solution.

      Delete
    4. Hi guys, Do someone find a solution for Salha problem?

      Delete
    5. I don't think that is possible. Easiest solution will be to use "Go to section based on this question". That will work only if there is not too many options of options.

      Delete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Excellent, and well commented within the code. Many Thanks

    ReplyDelete
  9. I was hoping this was the answer to my challenge, but not quite. Is it possible to capture the value chosen in say DropDown1, and use that value to determine which list of values are selected on the spreadsheet to go into Dropdown2. e.g. Dropdown1 contains "Fruit" "Vegetables" "Meat". If I chose Fruit in Dropdown1, then DropDown2 shows "Apple" Orange" "Banana", if I choose Meat then DropDown2 shows "Lamb" Beef" "Chicken". I guess it is about being able to capture that live value?

    ReplyDelete
    Replies
    1. Forgot to add, I know I can use conditional branching on the form, but this adds far too many columns in the spreadsheet.

      Delete
    2. You are correct, this cannot solve required problem. That will need some enhancement at javascript level. I don't think google forms has that yet.

      Delete
  10. Thanks, further research has shown this to be the case for now. The missing link for google forms in my opinion. Thanks for your work.

    ReplyDelete
  11. can you give example what problem actually your code solves?

    I am looking for a way such that in one dropdown I select an unique ID, and in next dropdown the name is autoselected.

    ReplyDelete
    Replies
    1. Currently I don't think we have any way in which you can change dropdown options using javascript / ajax etc.

      Delete
  12. Dear Nitin . how to get the ID of yr Google Form

    ReplyDelete
    Replies
    1. Hi,

      When you are creating a google form, you will see url like- https://docs.google.com/forms/d/abcdefghijklXT_Nkfl_9Lno392I6Ue4pu4tToaPkO-21E/edit. Form Id for this form is abcdefghijklXT_Nkfl_9Lno392I6Ue4pu4tToaPkO-21E.

      Delete
    2. Sorry for bad formatting of text above. :)

      Delete