summaryrefslogtreecommitdiff
path: root/src/js/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/index.js')
-rw-r--r--src/js/index.js50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/js/index.js b/src/js/index.js
index 21adad5..0697b51 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -1,12 +1,9 @@
-
/*
* Adds an event listener to all burgers to toggle navbar menu on click.
*/
document.addEventListener('DOMContentLoaded', function () {
- // get all navbar-burger elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
- // check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// add a click event on each of them
$navbarBurgers.forEach(function(el) {
@@ -23,11 +20,34 @@ document.addEventListener('DOMContentLoaded', function () {
}
});
-document.forms.inquiry.onsubmit = function() {
+const disableErrorBox = function() {
+ document.getElementById("errorBox").style.display = "none";
+}
+
+const disableSuccessBox = function() {
+ document.getElementById("successBox").style.display = "none";
+}
+
+const enableErrorBox = function(message) {
let errorBox = document.getElementById("errorBox");
- let successBox = document.getElementById("successBox");
- errorBox.style.display = "none";
- successBox.style.display = "none";
+ let aTag = document.createElement('a');
+ aTag.setAttribute("href", "mailto:amy@carpentertutoring.com");
+ aTag.innerText = message + " Click here to send through your mail client.";
+ while (errorBox.hasChildNodes()) { errorBox.removeChild(errorBox.lastChild); }
+ errorBox.appendChild(aTag);
+ errorBox.style.display = "block";
+}
+
+const enableSuccessBox = function() {
+ document.getElementById("successBox").style.display = "block";
+}
+
+/*
+ * Adds mail sender to form submit.
+ */
+document.forms.inquiry.onsubmit = function() {
+ disableErrorBox();
+ disableSuccessBox();
let form = document.forms.inquiry;
let name = form.elements.name.value;
let fromEmail = form.elements.from.value;
@@ -40,20 +60,12 @@ document.forms.inquiry.onsubmit = function() {
Subject : "Inquiry: " + name,
Body : body,
}).then( message => {
- if (message != "OK") {
- let link = "<a href=mailto:amy@carpentertutoring> Click here to send through your mail client.</a>"
- let aTag = document.createElement('a');
- aTag.setAttribute("href", "mailto:amy@carpentertutoring.com");
- aTag.innerText = message + " Click here to send through your mail client.";
- while (errorBox.hasChildNodes()) {
- errorBox.removeChild(errorBox.lastChild);
- }
- errorBox.appendChild(aTag);
- errorBox.style.display = "block";
+ if (message == "OK") {
+ form.reset();
+ enableSuccessBox();
}
else {
- form.reset();
- successBox.style.display = "block";
+ enableErrorBox(message);
}
}
);