Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Working Stopwatch & Working Web Form API
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Stopwatch App</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<h1>Week 9 Stopwatch</h1> | ||
<button id="start">Start</button> | ||
<button id="stop">Stop</button> | ||
<p id="timer">Seconds Passed: </p> | ||
</div> | ||
|
||
<script src="main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
let startBtn = document.querySelector('#start') | ||
let stopBtn = document.querySelector('#stop') | ||
let intervalId; | ||
let timer = document.querySelector('#timer') | ||
let counter = 0; | ||
|
||
function change(){ | ||
timer.innerHTML = "Seconds Passed: " + counter; | ||
} | ||
|
||
startBtn.addEventListener('click', function(){ | ||
intervalId = setInterval(function(){ | ||
console.log('1 second has passed') | ||
counter += 1; | ||
change(); | ||
}, 1000) | ||
}) | ||
|
||
stopBtn.addEventListener('click', function(){ | ||
clearInterval(intervalId) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#container { | ||
border: solid; | ||
border-radius: 3em; | ||
padding: 1em; | ||
display: inline-block; | ||
text-align: center; | ||
} | ||
|
||
body { | ||
display: flex; | ||
justify-content: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Week 8 Part 2</title> | ||
</head> | ||
<body> | ||
<form id="emailForm" action="https://formspree.io/f/xyyodebw" method="POST"> | ||
<input type="text" name="name" placeholder="Name"><br> | ||
<input type="text" name="email" placeholder="Email"><br> | ||
<input type="text" name="subject" placeholder="Subject"><br> | ||
<input type="text" name="message" placeholder="Message"><br> | ||
|
||
|
||
|
||
<input type="submit" value="Send Message"> | ||
<p id="my-form-status"></p> | ||
</form> | ||
|
||
|
||
|
||
<script src="emailForm.js"></script> | ||
<script> | ||
var form = document.getElementById("emailForm"); | ||
|
||
async function handleSubmit(event) { | ||
event.preventDefault(); | ||
var status = document.getElementById("my-form-status"); | ||
var data = new FormData(event.target); | ||
fetch(event.target.action, { | ||
method: form.method, | ||
body: data, | ||
headers: { | ||
'Accept': 'application/json' | ||
} | ||
}).then(response => { | ||
if (response.ok) { | ||
status.innerHTML = "Thanks for your submission!"; | ||
form.reset() | ||
} else { | ||
response.json().then(data => { | ||
if (Object.hasOwn(data, 'errors')) { | ||
status.innerHTML = data["errors"].map(error => error["message"]).join(", ") | ||
} else { | ||
status.innerHTML = "Oops! There was a problem submitting your form" | ||
} | ||
}) | ||
} | ||
}).catch(error => { | ||
status.innerHTML = "Oops! There was a problem submitting your form" | ||
}); | ||
} | ||
form.addEventListener("submit", handleSubmit) | ||
</script> | ||
</body> | ||
</html> |