【发布时间】:2015-03-07 11:47:42
【问题描述】:
似乎我几乎可以使用它,但由于某种原因,当我尝试将输入字段中的数据提交到 Google 电子表格时,它确实添加了数据,但没有添加正在输入的数据。因此,在 Google 电子表格中,我看到了一个带有时间戳的新条目,但没有看到输入的数据。
代码如下:
<script>
$('#emailForm').one('submit',function(){
var inputField = encodeURIComponent($('#emailForm').val());
var baseURL = 'http://docs.google.com/forms/d/1vl7imylKoya3y8bnboD7WTQ5VsdVw1YmDA1-3_66Apo/formResponse?entry.1017875735=';
var submitRef = '&submit=Submit';
var submitURL = (baseURL + emailAddress + submitRef);
$(this)[0].action=submitURL;
$('#email').addClass('active').val('Thank You!');
setTimeout(function(){
$('#form-container').hide();
$('#update-form').animate({'width': '0px'},300,function(){
$('#get-updates-link').hide();
$('#email').addClass('active').val('Thank You!');
});
},1000);
</script>
<form action="https://docs.google.com/forms/d/1vl7imylKoya3y8bnboD7WTQ5VsdVw1YmDA1-3_66Apo/formResponse?entry.1017875735="
<form id="emailForm" action="" method="POST" target="no-target">
<input id="email" type="email" placeholder="enter email" name="email">
<button id="email-submit" type="submit"></button>
</form>
【问题讨论】:
-
这个问题有点傻,但是你在哪里使用'inputField'变量?据我了解,此变量包含输入字段的值,但不会发送到电子表格...
-
这行好像应该是
var emailAddress = encodeURIComponent($("#email").val());。 -
FWIW:这是我用来测试代码的a fiddle。不幸的是,JSFiddle 不能很好地处理表单。我无法阻止默认提交操作,但我可以使用 keyup 事件来查看数据是否在正确的位置。
标签: javascript jquery html forms google-sheets