-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (72 loc) · 2.61 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Theme Button Function
(function () {
[...document.querySelectorAll(".control")].forEach((button) => {
button.addEventListener("click", function () {
document.querySelector(".active-btn").classList.remove("active-btn");
this.classList.add("active-btn");
document.querySelector(".active").classList.remove("active");
document.getElementById(button.dataset.id).classList.add("active");
});
});
document.querySelector(".theme-btn").addEventListener("click", () => {
document.body.classList.toggle("light-mode");
});
})();
//Age Automatically Updates in Paragraph
const birthDate = new Date("2004-08-19");
function calculateAge() {
const today = new Date();
const age = today.getFullYear() - birthDate.getFullYear();
// Check if birthday has occurred this year
if (
today.getMonth() < birthDate.getMonth() ||
(today.getMonth() === birthDate.getMonth() &&
today.getDate() < birthDate.getDate())
) {
document.getElementById("agebold").innerText = age - 1; // Subtract 1 if birthday hasn't occurred yet
} else {
document.getElementById("agebold").innerText = age;
}
}
setInterval(calculateAge, 1000);
//Newer Google Sheet App Script Connection
document.addEventListener("DOMContentLoaded", function () {
var form = document.getElementById("myform");
var url =
"https://script.google.com/macros/s/AKfycbwTVyK2PUBa1wys5WBpD-H81tutzxw6-463RWPFkmtv8OVoN573TEZJYpXESCkm9HlHWw/exec";
form.addEventListener("submit", function (e) {
e.preventDefault();
var formData = new FormData(form);
fetch(url, {
method: "POST",
body: formData,
})
.then(function (response) {
if (response.ok) {
//Message to alert whether Form is succesfully Submitted
alert("Form submitted successfully!");
} else {
throw new Error("Network response was not ok.");
}
})
.catch(function (error) {
//Error Message if my Form Submittion Fails
alert("Error submitting the form. Please try again.");
console.error("Error:", error);
});
});
});
//Older Google Sheet App Script Connection
// var $form = $('form#test-form'),
// url = 'https://script.google.com/macros/s/AKfycbwTVyK2PUBa1wys5WBpD-H81tutzxw6-463RWPFkmtv8OVoN573TEZJYpXESCkm9HlHWw/exec'
// $('#submit-form').on('click', function(e) {
// e.preventDefault();
// var jqxhr = $.ajax({
// url: url,
// method: "GET",
// dataType: "json",
// data: $form.serializeObject()
// }).success(
// // do something
// );
// })