Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
2024-spring-dmd-3475/week-11/index.html
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (35 sloc)
1.23 KB
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Email Form</title> | |
</head> | |
<body> | |
<h1>Email Form</h1> | |
<form id="emailForm"> | |
<label for="to">To:</label> | |
<input type="email" id="to" name="to" required><br><br> | |
<label for="subject">Subject:</label> | |
<input type="text" id="subject" name="subject" required><br><br> | |
<label for="message">Message:</label><br> | |
<textarea id="message" name="message" rows="4" cols="50" required></textarea><br><br> | |
<button type="submit">Send</button> | |
</form> | |
<script> | |
const form = document.getElementById('emailForm'); | |
form.addEventListener('submit', async (event) => { | |
event.preventDefault(); | |
const formData = new FormData(form); | |
const data = Object.fromEntries(formData); | |
const response = await fetch('https://jsonplaceholder.typicode.com/posts', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify(data) | |
}); | |
const result = await response.json(); | |
alert(`Your message has been sent: ${result.message}`); | |
}); | |
</script> | |
</body> | |
</html> |