From f060f2564bc376fc25b7b92c0e8f1cf1cdc3ceaa Mon Sep 17 00:00:00 2001 From: Jahnavika gopal <120931967+JahnavikaGopalbvrith@users.noreply.github.com> Date: Sun, 20 Oct 2024 21:38:17 +0530 Subject: [PATCH] Update main.html --- donation/main.html | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/donation/main.html b/donation/main.html index 47a9c67..a904caa 100644 --- a/donation/main.html +++ b/donation/main.html @@ -267,6 +267,86 @@

Select Amount

alert("Donation Submitted:\n\n" + donationMessage); } + // JavaScript to handle the donation process +function donateNow() { + const name = document.getElementById('name').value; + const email = document.getElementById('email').value; + const coverTransaction = document.getElementById('coverTransaction').checked; + const frequency = document.getElementById('giftFrequency').checked ? 'Monthly' : 'One-Time'; + + // Regular expression for validating email format + const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + const gmailPattern = /^[^\s@]+@gmail\.com$/; // Pattern for specific Gmail address + + if (!name || !email || selectedAmount === 0) { + alert("Please fill out all fields and select an amount."); + return; + } + + if (!emailPattern.test(email)) { + alert("Please enter a valid email address."); + return; + } + + if (!gmailPattern.test(email)) { + alert("Please enter a Gmail address (e.g., example@gmail.com)."); + return; + } + + let donationMessage = `Name: ${name}\nEmail: ${email}\nDonation Frequency: ${frequency}\nAmount: ₹${selectedAmount}`; + if (coverTransaction) { + donationMessage += "\nYou opted to cover ₹50 for transaction fees."; + } + + alert("Donation Submitted:\n\n" + donationMessage); +} +// JavaScript to handle the donation process +function donateNow() { + const nameField = document.getElementById('name'); + const emailField = document.getElementById('email'); + const coverTransaction = document.getElementById('coverTransaction').checked; + const frequency = document.getElementById('giftFrequency').checked ? 'Monthly' : 'One-Time'; + + const name = nameField.value; + const email = emailField.value; + + // Regular expression for validating email format + const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + const gmailPattern = /^[^\s@]+@gmail\.com$/; // Pattern for specific Gmail address + + if (!name || !email || selectedAmount === 0) { + alert("Please fill out all fields and select an amount."); + return; + } + + if (!emailPattern.test(email)) { + alert("Please enter a valid email address."); + return; + } + + if (!gmailPattern.test(email)) { + alert("Please enter a Gmail address (e.g., example@gmail.com)."); + return; + } + + let donationMessage = `Name: ${name}\nEmail: ${email}\nDonation Frequency: ${frequency}\nAmount: ₹${selectedAmount}`; + if (coverTransaction) { + donationMessage += "\nYou opted to cover ₹50 for transaction fees."; + } + + alert("Donation Submitted:\n\n" + donationMessage); + + // Reset the form fields + nameField.value = ''; + emailField.value = ''; + document.getElementById('coverTransaction').checked = false; + selectedAmount = 0; // Reset selected amount + document.querySelectorAll('.amount-buttons button').forEach(button => { + button.classList.remove('selected'); // Optionally, remove selection from buttons + }); +} + +