如何从html表单向谷歌电子表格发送数据

时间:2016-06-10 07:25:38

标签: javascript html spreadsheet

我有Lname Fname输入,我想将其值发送到谷歌电子表格。我怎么做?请你为新手提供一些简单的方法或教程。谷歌api开发者指南太混乱了

1 个答案:

答案 0 :(得分:2)

<!DOCTYPE html>
<html>
    <head>
        <title>Test Google Forms</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    </head>
    <body>
        <div>
            <div>
                <strong>Test Google Form</strong>
            </div>
            <form id="form" target="_self" onsubmit="" action="">
                <fieldset>
                    <label>Question 1</label>
                    <input id="qs1_op_1" type="radio" value="Yes" name="qs1">
                    <input id="qs1_op_2" type="radio" value="No" name="qs1">
                </fieldset>
                <fieldset>
                    <label>Question 2</label>
                    <input id="qs2_op_1" type="radio" value="Yes" name="qs2">
                    <input id="qs2_op_2" type="radio" value="No" name="qs2">
                </fieldset>
                <fieldset>
                    <label>Text</label>
                    <textarea id="feed" name="feed"></textarea>
                </fieldset>
                <div style="width: 100%; display: block; float: right;">
                    <button id="send" type="submit">
                        Send
                    </button>
                </div>
            </form>
        </div>
        <script type="text/javascript">
            function postToGoogle() {
                var field1 = $("input[type='radio'][name='qs1']:checked").val();
                var field2 = $("input[type='radio'][name='qs2']:checked").val();
                var field3 = $('#feed').val();
 
                $.ajax({
                    url: "https://docs.google.com/forms/d/FORM_KEY/formResponse",
                    data: {"entry.1023121230": field3, "entry.1230072460": field1, "entry.2113237615": field2},
                    type: "POST",
                    dataType: "xml",
                    statusCode: {
                        0: function() {
                            //Success message
                        },
                        200: function() {
                            //Success Message
                        }
                    }
                });
            }
             
            $(document).ready(function(){
                $('#form').submit(function() {
                    postToGoogle();
                    return false;
                });
            });
        </script>
    </body>
</html>

有关更多detils,请检查这些链接 https://wiki.base22.com/pages/viewpage.action?pageId=72942000

http://quandaflow.com/