-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (34 loc) · 1.22 KB
/
script.js
File metadata and controls
39 lines (34 loc) · 1.22 KB
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
let students = [];
document.getElementById("addStd").addEventListener('click', (e) => {
e.preventDefault();
const name = document.getElementById('name').value;
const dob = document.getElementById('DOB').value;
const address = document.getElementById('address').value;
const phone = document.getElementById('phone').value;
const email = document.getElementById('email').value;
if (name && dob && address && phone && email) {
const student = {
name,
dob,
address,
phone,
email
};
students.push(student);
document.getElementById('stdForm').reset();
alert('Student added successfully!');
} else {
alert('Please fill out all fields');
}
});
document.getElementById("data").addEventListener('click', () => {
const outputDiv = document.getElementById('output');
if (students.length === 0) {
outputDiv.innerHTML = '<p>No student data available</p>';
} else {
const jsonData = JSON.stringify(students, null, 2);
outputDiv.innerHTML = `<pre>${jsonData}</pre>`;
}
// Show the output div when button is clicked
outputDiv.style.display = 'block';
});