JAYASWAROOP commited on
Commit
009a455
·
verified ·
1 Parent(s): 96656a7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +35 -23
index.html CHANGED
@@ -377,32 +377,44 @@
377
  easing: 'ease', // Easing option
378
  once: true // Only animate elements once
379
  });
380
- document.addEventListener("DOMContentLoaded", function() {
381
- const contactForm = document.getElementById("contactForm");
382
 
383
- contactForm.addEventListener("submit", function(event) {
384
- event.preventDefault(); // Prevent the default form submission
385
-
386
- // Retrieve form data
387
- const name = document.getElementById("name").value;
388
- const email = document.getElementById("email").value;
389
- const message = document.getElementById("message").value;
390
-
391
- // Construct the email body
392
- const emailBody = `Name: ${name}\nEmail: ${email}\nMessage:\n${message}`;
393
-
394
- // Send the email using Gmail API (configure your credentials)
395
- // Replace with your actual Gmail API code
396
-
397
- // Example: Log the form data (replace with Gmail API code)
398
- console.log("Name:", name);
399
- console.log("Email:", email);
400
- console.log("Message:", message);
401
-
402
- // Optionally, display a success message to the user
403
- alert("Thank you! Your message has been sent.");
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  });
405
  });
 
406
  </script>
407
  </body>
408
  </html>
 
377
  easing: 'ease', // Easing option
378
  once: true // Only animate elements once
379
  });
 
 
380
 
381
+ const form = document.querySelector('form');
382
+
383
+ form.addEventListener('submit', (event) => {
384
+ event.preventDefault(); // Prevent default form submission
385
+
386
+ const name = document.getElementById('name').value;
387
+ const email = document.getElementById('email').value;
388
+ const message = document.getElementById('message').value;
389
+
390
+ // Construct email content
391
+ const body = `
392
+ Name: ${name}\n
393
+ Email: ${email}\n
394
+ Message:\n
395
+ ${message}
396
+ `;
397
+
398
+ // Optional: Add validation for name, email, and message
399
+
400
+ // Send email using a dedicated library or service
401
+ // Example using a hypothetical library:
402
+ sendEmail({
403
404
+ subject: 'New Contact Form Submission',
405
+ body: body,
406
+ })
407
+ .then(() => {
408
+ // Clear form fields and display a success message
409
+ form.reset();
410
+ alert('Message sent successfully!');
411
+ })
412
+ .catch((error) => {
413
+ console.error('Error sending email:', error);
414
+ alert('An error occurred while sending the message. Please try again.');
415
  });
416
  });
417
+
418
  </script>
419
  </body>
420
  </html>