Skip to content

Instantly share code, notes, and snippets.

@kellyegan
Created May 5, 2016 19:36
Show Gist options
  • Save kellyegan/512c3972d850a8b0f216a856266594f1 to your computer and use it in GitHub Desktop.
Save kellyegan/512c3972d850a8b0f216a856266594f1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Test Google Forms</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<h1 id="title">Test Google Form</h1>
<form id="form" target="_self" onsubmit="" action="">
<fieldset>
<label>Name</label>
<textarea id="name" name="name"></textarea>
</fieldset>
<fieldset>
<label>Occupation</label>
<textarea id="occupation" name="occupation"></textarea>
</fieldset>
<div style="width: 100%; display: block; float: right;">
<button id="send" type="submit">
Send
</button>
</div>
</form>
</div>
<script src="https://code.jquery.com/jquery-1.12.3.min.js" integrity="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ=" crossorigin="anonymous"></script>
<script type="text/javascript">
function postToGoogle() {
var name = $('#name').val();
var occupation = $('#occupation').val();
$.ajax({
url: "https://docs.google.com/forms/d/1lgT96Fbwm5zaZUOqVF1i4X11Om2Xdo71HSMuQCvqtm4/formResponse",
data: {
"entry.645898436": name,
"entry.2036385529": occupation
},
type: "POST",
dataType: "jsonp",
statusCode: {
0: function () {
$("title").text = "Failed!"
console.log("Failed!");
},
200: function () {
$("title").text = "Success!"
console.log("Success!");
}
}
});
}
$(document).ready(function () {
$('#form').submit(function () {
postToGoogle();
return false;
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment