在表单提交上执行JavaScript

时间:2015-01-12 20:21:44

标签: javascript forms google-apps-script

我在图层上显示了一个表单(我使用ChicoUI作为UI Framework),所有内容都通过Google Apps脚本管理。一切都很顺利(提交将数据发送到谷歌电子表格),但我需要以下内容:当按下提交按钮时,我需要通过简单的js行更改图层内容。使用关闭按钮显示经典的“谢谢消息”。

据我所见,一切都会导致在gs脚本中返回一些内容,例如在doGet()方法中。

执行框架方法而不是返回某些内容是否可行?请记住,我对JS没有任何问题,但使用Google Apps脚本。

提前多多感谢!

1 个答案:

答案 0 :(得分:0)

这是我用jQuery做的一个例子。我认为理解你想要达到的目标可能会有所帮助。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
    $(document).ready(function() {
      $("#myform").submit(function(event) {
        event.preventDefault();
        google.script.run.withSuccessHandler(function(e){
           alert("Thank you"); // Here you can write thank you message.
        }).myFunction(this);  // passing forms data to apps script.
      });
    });
</script>

<form id="myform">                   
  <input name="user1" id="user" type="text" value="">
  <input name="user2" id="user" type="text" value="">
  <input name="user3" id="user" type="text" value="">
  <input type="submit" value="Submit Form"> 
</form>
相关问题