Skip to content
Permalink
ae5f3fadd5
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
43 lines (35 sloc) 1.23 KB
<!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>