【问题标题】:Dynamically fill form fields based on other responses before submit提交前根据其他响应动态填写表单字段
【发布时间】:2014-07-07 05:51:10
【问题描述】:

我有一个想要动态更改的表格,我已经阅读了文档,但似乎找不到任何明确的答案。我可以让我的表单从下拉列表中删除选择,因为他们在第三个问题中使用了单选按钮 #2?我可以对问题 1 中的文本进行格式化,并使用它以相同的答案预先填写问题 6(默认情况下,需要更改)吗?

基本上,我需要使用代码来确定地址是否用缩写形式(st、rd、cres、ct)拼写,并将它们加长和大写(Street、Road)。我什至不知道这是否可能。如果有人可以提供示例代码或将我指向正确的帮助文档,将不胜感激。如果不是,如果我的一些多项选择选项需要从谷歌电子表格中读取,这在网络服务器上是否可行?我可以通过 Google 协作平台进行吗?

【问题讨论】:

    标签: google-apps-script google-sites google-forms


    【解决方案1】:

    您看过Form Google Apps 服务类吗?

    Class Forms

    它说:

    可以从 FormApp 访问或创建表单。

    例如,您可以使用:

    addTextItem()
    

    或者:

    createChoice(value)
    

    Google Documentation

     // Open a form by ID and add a new multiple choice item.
     var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
     var item = form.addMultipleChoiceItem();
     item.setTitle('Do you prefer cats or dogs?')
         .setChoices([
             item.createChoice('Cats'),
             item.createChoice('Dogs')
          ])
         .showOtherOption(true);
    

    您不想打开新表单,而是使用当前打开的表单。

    /**
     * Adds a custom menu to the active form, containing a single menu item for
     * invoking checkResponses() specified below.
     */
    function onOpen() {
      FormApp.getUi()
          .createMenu('My Menu')
          .addItem('Check responses', 'checkResponses')
          .addToUi();
    }
    

    检查当前的响应?

    /**
     * Gets the list of responses and checks the average rating from the form
     * created in createForm() above.
     */
    function checkResponses() {
      var form = FormApp.getActiveForm();
      var responses = form.getResponses();
      var score = 0;
      for (var i = 0; i < responses.length; i++) {
        var itemResponses = responses[i].getItemResponses();
        for (var j = 0; j < itemResponses.length; j++) {
          var itemResponse = itemResponses[j];
          if (itemResponse.getItem().getType() == FormApp.ItemType.SCALE) {
            score += itemResponse.getResponse();
          }
        }
        var average = score / responses.length;
        FormApp.getUi().alert('The score is ' + average);
      }
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用 Apps Script HTML 服务;编写 HTML 以创建自定义表单;编写 JavaScript 代码来做你想做的事;然后将 Apps 脚本添加到 Google 站点。或者只是将 Apps 脚本 HTML 服务作为自己的网站运行。但此选项要求您能够编写 HTML 和 JavaScript。你想做什么都是可能的。

      就创建自定义表单、检查用户输入和更改它而言,这可以在 Apps Script HTML Service 中完成。然后,您需要将数据保存在某处。 Google 表单旨在为没有编程知识的人提供用户友好。

      您似乎只是在寻找有关不同产品可能和不可能的一般信息,以便您做出选择。

      要阅读有关 HTML 服务的信息,请单击以下链接作为起点:

      Google Documentation HTML Service

      【讨论】:

      • 我有 HTML 经验、js 经验和 CSS,我真的希望得到一个像你可以使用 getLiveResponses(e) 的答案;并创建一个新问题或其他东西......看起来我将不得不以艰难的方式做到这一点:(不过感谢您的帮助。
      猜你喜欢
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多