-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (119 loc) · 4.49 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
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
// Hamburger menu function
const hamburger=document.getElementById('hamburger');
const mobileMenu=document.getElementById('mobile-menu');
hamburger.addEventListener('click',function(){
mobileMenu.classList.toggle('active')
});
document.addEventListener('DOMContentLoaded',function(){
const hamburger=document.getElementById('hamburger');
const mobileMenu=document.getElementById('mobile-menu');
hamburger.addEventListener('click',function(){
mobileMenu.classList.toggle('active')
});
const form = document.getElementById('enq');
const popup = document.getElementById('popup');
const okBtn = document.getElementById('ok');
let formSubmit=false;
popup.style.display = 'none';
form.addEventListener('submit', function (event) {
// Prevent the default form submission
event.preventDefault();
popup.style.display = 'block';
// Get the form and its elements
const form = document.getElementById('enq');
const nameInput = document.getElementById('name');
const emailInput = document.getElementById('mail');
const phoneInput = document.getElementById('phone');
// Add an event listener to the form's submit event
form.addEventListener('submit', (e) => {
// Prevent the form from submitting by default
e.preventDefault();
// Validate the name input
if (!validateName(nameInput.value)) {
alert('Name should contain only alphabets');
return;
}
// Validate the email input
if (!validateEmail(emailInput.value)) {
alert('Email should be in a proper format (e.g. example@example.com)');
return;
}
// Validate the phone input
if (!validatePhone(phoneInput.value)) {
alert('Phone number should contain only numbers');
return;
}
// If all inputs are valid, submit the form
form.submit();
});
// Function to validate the name input
function validateName(name) {
const nameRegex = /^[a-zA-Z ]+$/;
return nameRegex.test(name);
}
// Function to validate the email input
function validateEmail(email) {
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailRegex.test(email);
}
// Function to validate the phone input
function validatePhone(phone) {
const phoneRegex = /^\d+$/;
return phoneRegex.test(phone);
}
});
//Form submission popup
okBtn.addEventListener('click', function () {
popup.style.display = 'none';
});
//how popup works when clicked on submit or on window
window.addEventListener('click', function (event) {
if (event.target == form || event.target == okBtn || !popup.contains(event.target)) {
popup.style.display = 'none';
}
});
});
//Function for displaying the course details
document.getElementById('course').addEventListener('change', function() {
// Hide all tables
document.querySelectorAll('.crstable').forEach(function(table) {
table.style.display = 'none';
});
// Show the selected table
const selectedTable = document.getElementById(this.value);
if (selectedTable) {
selectedTable.style.display = 'block';
}
});
// Script to handle course and semester selection and display the corresponding timetable
document.addEventListener('DOMContentLoaded', function() {
const courseSelect = document.getElementById('course-select');
const semesterSelect = document.getElementById('semester-select');
function displayTimetable(course, semester) {
// Hide all tables
const allTables = document.querySelectorAll('.timetable');
allTables.forEach(table => table.style.display = 'none');
// Construct the ID of the table to show
const tableId = `${course}-${semester}`;
const selectedTable = document.getElementById(tableId);
// Show the selected table if it exists
if (selectedTable) {
selectedTable.style.display = 'table';
}
}
//Examination details selected based on course and semesters
courseSelect.addEventListener('change', function() {
const course = courseSelect.value;
const semester = semesterSelect.value;
if (course && semester) {
displayTimetable(course, semester);
}
});
semesterSelect.addEventListener('change', function() {
const course = courseSelect.value;
const semester = semesterSelect.value;
if (course && semester) {
displayTimetable(course, semester);
}
});
});