From 5d557866118c141f8e6b0d305384d7f87d28b806 Mon Sep 17 00:00:00 2001 From: Emily HK Date: Thu, 20 Jun 2024 16:20:34 -0600 Subject: [PATCH] Added all JavaScript --- JAVASCRIPT/carousel.js | 49 +++++++++++++++++++++++++ JAVASCRIPT/submitbooking.js | 73 +++++++++++++++++++++++++++++++++++++ JAVASCRIPT/submitcontact.js | 46 +++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 JAVASCRIPT/carousel.js create mode 100644 JAVASCRIPT/submitbooking.js create mode 100644 JAVASCRIPT/submitcontact.js diff --git a/JAVASCRIPT/carousel.js b/JAVASCRIPT/carousel.js new file mode 100644 index 0000000..04a2238 --- /dev/null +++ b/JAVASCRIPT/carousel.js @@ -0,0 +1,49 @@ +/* + Emily Hartz-Kuzmicz + job346 + 11350337 + CMPT281 +*/ + +let slideIndex = 1; +displaySlides(slideIndex); + +/* +Changes the image based on which (< >) button is pressed. + +Parameters: + n: An integer to add to slideIndex, then pass to + displaySlides to show the new image. +*/ +function changeSlides(n) { + displaySlides(slideIndex += n); +} + +/* +Displays a single carousel image. + +Parameters: + n: An integer index value to access the image in the + array of carousel images. +*/ +function displaySlides(n) { + let i; + let slides = document.getElementsByClassName("CarouselImage"); + + //If the index is greater than the array length + if (n > slides.length) { + slideIndex = 1; + + //If the index is smaller than the smallest array index + } else if (n < 1) { + slideIndex = slides.length; + } + + //Sets all images to display=none + for (i = 0; i < slides.length; i++) { + slides[i].style.display = "none"; + } + + //Shows a single image + slides[slideIndex-1].style.display = "initial"; +} \ No newline at end of file diff --git a/JAVASCRIPT/submitbooking.js b/JAVASCRIPT/submitbooking.js new file mode 100644 index 0000000..963b984 --- /dev/null +++ b/JAVASCRIPT/submitbooking.js @@ -0,0 +1,73 @@ +/* + Emily Hartz-Kuzmicz + job346 + 11350337 + CMPT281 +*/ + +/* +Submits the form on the "Booking" Page. +*/ +function formSubmit() { + let loginForm = document.getElementById("Form"); + + loginForm.addEventListener("submit", (e) => { + e.preventDefault(); + + //Take in all data from form + let fname = document.getElementById("fname"); + let lname = document.getElementById("lname"); + let phonenum = document.getElementById("phonenum"); + let email = document.getElementById("email"); + let returning_patient, contact_method; + + //Check which radio button is selected for returning patient + if (document.getElementById("returning_patientyes").checked) { + returning_patient = "yes"; + } else { + returning_patient = "no"; + } + + //Check which radio button is selected for contact method + if (document.getElementById("contact_methodphone").checked) { + contact_method = "phone"; + } else { + contact_method = "email"; + } + + let day = document.getElementById("day"); + let time = document.getElementById("time"); + let message = document.getElementById("message"); + + //If any of the required field values are empty + if (fname.value == "" || lname.value == "" || phonenum.value == "" || email.value == "" || message.value == "") { + alert("The following values cannot be empty: First Name, Last Name, Phone Number, Email."); + + } else { + alert("Your appointment request has been successfully submitted!"); + + //Log the given data to the console + console.log( + `First Name: ${fname.value}\nLast Name: ${lname.value}\nPhone Number: ${phonenum.value}\nEmail: ${email.value}\n` + ); + + console.log( + `Returning Patient: ${returning_patient}\nContact Method: ${contact_method}\n` + ); + + console.log( + `Requested Day: ${day.value}\nRequested Time: ${time.value}\nMessage: ${message.value}\n` + ); + + //Set all values back to empty + fname.value = ""; + lname.value = ""; + phonenum.value = ""; + email.value = ""; + + day.value = "monday"; + time.value = "9"; + message.value = ""; + } + }); +} \ No newline at end of file diff --git a/JAVASCRIPT/submitcontact.js b/JAVASCRIPT/submitcontact.js new file mode 100644 index 0000000..e66907a --- /dev/null +++ b/JAVASCRIPT/submitcontact.js @@ -0,0 +1,46 @@ +/* + Emily Hartz-Kuzmicz + job346 + 11350337 + CMPT281 +*/ + +/* +Submits the form on the "Contact Us" Page. +*/ +function formSubmit() { + let loginForm = document.getElementById("Form"); + + loginForm.addEventListener("submit", (e) => { + e.preventDefault(); + + //Take in all data from form + let fname = document.getElementById("fname"); + let lname = document.getElementById("lname"); + let phonenum = document.getElementById("phonenum"); + let email = document.getElementById("email"); + let subject = document.getElementById("subject"); + let message = document.getElementById("message"); + + //If any of the required field values are empty + if (fname.value == "" || lname.value == "" || phonenum.value == "" || email.value == "" || subject.value == "" || message.value == "") { + alert("The following values cannot be empty: First Name, Last Name, Phone Number, Email, Subject, Message."); + + } else { + alert("Your contact request has been successfully submitted!"); + + //Log the given data to the console + console.log( + `First Name: ${fname.value}\nLast Name: ${lname.value}\nPhone Number: ${phonenum.value}\nEmail: ${email.value}\nSubject: ${subject.value}\nMessage: ${message.value}` + ); + + //Set all values back to empty + fname.value = ""; + lname.value = ""; + phonenum.value = ""; + email.value = ""; + subject.value = ""; + message.value = ""; + } + }); +} \ No newline at end of file