-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.js
139 lines (100 loc) · 3.93 KB
/
contact.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
document.addEventListener("DOMContentLoaded", () => {
const moveableElements = document.querySelectorAll(".moveable-element");
moveableElements.forEach(element => {
element.addEventListener("mousemove", (event) => {
const rect = element.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const moveX = (x / rect.width) * 10 - 5;
const moveY = (y / rect.height) * 10 - 5;
element.style.transform = `translate(${moveX}px, ${moveY}px)`;
});
element.addEventListener("mouseleave", () => {
element.style.transform = "translate(0, 0)";
});
});
});
var bars = document.getElementById("nav-action");
var nav = document.getElementById("nav");
bars.addEventListener("click", barClicked, false);
function barClicked() {
bars.classList.toggle('active');
nav.classList.toggle('visible');
}
let mymenu =document.querySelector(".bars");
window.onscroll = function() {
if(window.scrollY>=100){
mymenu.style.display ="block";
}else{
mymenu.style.display="none"
}}
// when i final i well stat this
window.onload = function() {
let messages = ["Contact"];
let messageIndex = 0;
let myDivload = document.createElement("div");
myDivload.className = "temporary-message";
document.body.appendChild(myDivload);
function showNextMessage() {
if (messageIndex < messages.length) {
myDivload.innerHTML = `<div class="message-container"><div class="circle"></div><div>${messages[messageIndex]}</div></div>`;
myDivload.classList.remove('hidden');
setTimeout(function() {
myDivload.classList.add('hidden');
messageIndex++;
setTimeout(showNextMessage, 500);
}, 500);
} else {
myDivload.remove();
}
}
showNextMessage();
const currentTimeElement = document.getElementById('current-time');
const now = new Date();
let hours = now.getHours();
const minutes = now.getMinutes();
const ampm = hours >= 12 ? 'PM' : 'AM';
const minutesFormatted = minutes < 10 ? '0' + minutes : minutes;
const timeString = `${hours}:${minutesFormatted} ${ampm}`;
currentTimeElement.textContent = timeString;
};
document.getElementById('contactForm').addEventListener('submit', function(event) {
// Prevent form submission to check validation
event.preventDefault();
// Get form values
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const organization = document.getElementById('organization').value.trim();
const services = document.getElementById('services').value.trim();
const message = document.getElementById('message').value.trim();
// Regular Expressions
const nameRegex = /^[a-zA-Z\s]{3,}$/; // At least 3 characters, only letters and spaces
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; // Basic email validation
// Validate name
if (!nameRegex.test(name)) {
alert('Please enter a valid name (at least 3 characters and letters only).');
return false;
}
// Validate email
if (!emailRegex.test(email)) {
alert('Please enter a valid email address.');
return false;
}
// Validate message
if (message === "") {
alert('Please enter your message.');
return false;
}
// Optionally validate organization and services if required (can be left blank)
if (organization !== "" && !/^[a-zA-Z0-9\s]{3,}$/.test(organization)) {
alert('Please enter a valid organization name (at least 3 characters, letters and numbers only).');
return false;
}
if (services !== "" && !/^[a-zA-Z0-9\s,]{3,}$/.test(services)) {
alert('Please enter a valid services description.');
return false;
}
// If all validations pass, you can submit the form
alert('Form submitted successfully!');
this.submit(); // This will submit the form
});