Dynamically edit multiple choice options in live Google Form using Apps Script

I believe we can achieve your second objective without too much difficulty and modify the form, based on the current state of response.

The approach is to

  1. Create the form and associate it with a response spreadsheet
  2. In that response spreadsheet, create a script with a function (updateForm for instance)
  3. Bind that function with the onFormSubmit event, see Using Container-Specific Installable Triggers.
  4. Analyse the response in the updateForm function and modify your form using the Form Service

For instance

function updateForm(e) {
  if (e.values[1] == 'Yes') {
    Logger.log('Yes');
    var existingForm = FormApp.openById('1jYHXD0TBYoKoRUI1mhY4j....yLWGE2vAm_Ux7Twk61c');
    Logger.log(existingForm);
    var item = existingForm.addMultipleChoiceItem();
     item.setTitle('Do you prefer cats or dogs?')
     .setChoices([
         item.createChoice('Cats'),
         item.createChoice('Dogs')
      ])
     .showOtherOption(true);
  }
}

When it comes to achieving the goal in your first question, its more delicate, as the form will not submit mid way. What is possible is to go to different pages based on different responses to a Multiple Choice question, your use case may fit this method, although its not very dynamic.

Further its possible to use html Service to create completely dynamic experience.

Let me know if you need further information.

Leave a Comment