-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (25 loc) · 1.13 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
document.addEventListener('DOMContentLoaded', function() {
var form = document.getElementById('discountForm');
form.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent the default form submission behavior
var emailInput = document.getElementById('emailInput').value;
var codeInput = document.getElementById('codeInput').value;
var output = document.getElementById('output');
if (!isValidEmail(emailInput)) {
output.innerHTML = "Please enter a valid email address.";
return false; // Prevent form submission
}
if (codeInput.toLowerCase() === 'half') {
var discountAmount = 45000 * 0.15;
output.innerHTML = "You've got a 15% discount! Your discounted price is " + (45000 - discountAmount) + " shillings.";
} else {
output.innerHTML = "The total sum is 45000 shillings.";
}
return false; // Prevent form submission
});
function isValidEmail(email) {
// Regular expression for validating email format
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailPattern.test(email);
}
});