Z
Z
zzzz252015-04-13 18:19:03
JavaScript
zzzz25, 2015-04-13 18:19:03

How to submit form data to Google Spreadsheet using JavaScript?

Hello everyone,
I found an interesting tutorial https://wiki.base22.com/pages/viewpa...ageId=72942000 where Google Spreadsheet is used as a database.
I decided to try with a checkbox, the data is saved with only one checked checkbox. when I check both checkboxes, the spreadsheet cell remains empty

<form id="form" target="_self" onsubmit="" action="">
                <fieldset>
                    <label>Question 1</label>
                    <input id="qs1_op_1" class="ids" type="checkbox" value="Yes" name="qs1">
                    <input id="qs1_op_2" class="ids" type="checkbox" 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>
              
                <div style="width: 100%; display: block; float: right;">
                    <button id="send" type="submit">
                        Send
                    </button>
                </div>
            </form>

function postToGoogle() {


        var field1 = $.map($(':checkbox[name=qs1]:checked'), function(n, i){
        return n.value;
        }).join(',');
                var field2 = $("input[type='radio'][name='qs2']:checked").val();
       
 
                $.ajax({
                    url: "https://docs.google.com/forms/d/1Jr25MNbglMW4YZnabiCQ4HITLXq4U_70YyZeeoVGsn0/formResponse",
                    data: {"entry.1910683869": field1, "entry.1927167872": field2},
                    type: "POST",
                    dataType: "xml",
                    statusCode: {
                        0: function() {
                            //Success message
                        },
                        200: function() {
                            //Success Message
                        }
                    }
                });
            }
             
            $(document).ready(function(){
                $('#form').submit(function() {
                    postToGoogle();
                    return false;
                });
            });

Where is the mistake, how to transfer the values ​​of all checked checkboxes to one cell?
Link to form https://docs.google.com/forms/d/1Jr2...?usp=send_form
to spreadsheet https://docs.google.com/spreadsheets...#gid=110663523
Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question