secureloginflow-slider / student_data.html
Milind1996's picture
data is not saving to table wheni click on the add student
393a80a verified
Raw History Blame Contribute Delete
18.6 kB
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Data Entry</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.sheetjs.com/xlsx-0.19.3/package/dist/xlsx.full.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background-color: #0f172a;
color: #f8fafc;
}
.input-highlight {
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
transition: box-shadow 0.3s ease;
}
.text-gradient {
background: linear-gradient(90deg, #3b82f6, #60a5fa, #3b82f6);
background-size: 200% auto;
color: transparent;
background-clip: text;
-webkit-background-clip: text;
animation: shine 3s linear infinite;
}
@keyframes shine {
to {
background-position: 200% center;
}
}
.card-3d {
transform-style: preserve-3d;
perspective: 1000px;
box-shadow: 0 25px 50px -12px rgba(59, 130, 246, 0.25);
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-4xl mx-auto">
<div class="card-3d bg-gray-800 rounded-2xl overflow-hidden relative p-8">
<h1 class="text-3xl font-bold text-center mb-2 text-gradient">Student Data Entry</h1>
<p class="text-gray-400 text-center mb-8">Enter student details to export to Excel</p>
<form id="studentForm" class="space-y-4">
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label for="student-name" class="block text-sm font-medium text-gray-300 mb-1">Full Name</label>
<div class="relative">
<input type="text" id="student-name" name="name" required minlength="3"
class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded-lg focus:outline-none focus:border-blue-500 transition-all duration-300"
placeholder="John Doe">
<div class="absolute inset-0 rounded-lg pointer-events-none input-highlight hidden"></div>
</div>
</div>
<div>
<label for="student-id" class="block text-sm font-medium text-gray-300 mb-1">Student ID</label>
<div class="relative">
<input type="text" id="student-id" name="id" required
class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded-lg focus:outline-none focus:border-blue-500 transition-all duration-300"
placeholder="S12345">
<div class="absolute inset-0 rounded-lg pointer-events-none input-highlight hidden"></div>
</div>
</div>
<div>
<label for="student-age" class="block text-sm font-medium text-gray-300 mb-1">Age</label>
<div class="relative">
<input type="number" id="student-age" name="age" required min="5" max="25"
class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded-lg focus:outline-none focus:border-blue-500 transition-all duration-300"
placeholder="18">
<div class="absolute inset-0 rounded-lg pointer-events-none input-highlight hidden"></div>
</div>
</div>
</div>
<div>
<label for="student-address" class="block text-sm font-medium text-gray-300 mb-1">Address</label>
<div class="relative">
<textarea id="student-address" name="address" rows="2" required
class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded-lg focus:outline-none focus:border-blue-500 transition-all duration-300"
placeholder="123 Main St, City"></textarea>
<div class="absolute inset-0 rounded-lg pointer-events-none input-highlight hidden"></div>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label for="math-marks" class="block text-sm font-medium text-gray-300 mb-1">Math Marks</label>
<div class="relative">
<input type="number" id="math-marks" name="math" required min="0" max="100"
class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded-lg focus:outline-none focus:border-blue-500 transition-all duration-300"
placeholder="85">
<div class="absolute inset-0 rounded-lg pointer-events-none input-highlight hidden"></div>
</div>
</div>
<div>
<label for="science-marks" class="block text-sm font-medium text-gray-300 mb-1">Science Marks</label>
<div class="relative">
<input type="number" id="science-marks" name="science" required min="0" max="100"
class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded-lg focus:outline-none focus:border-blue-500 transition-all duration-300"
placeholder="90">
<div class="absolute inset-0 rounded-lg pointer-events-none input-highlight hidden"></div>
</div>
</div>
<div>
<label for="english-marks" class="block text-sm font-medium text-gray-300 mb-1">English Marks</label>
<div class="relative">
<input type="number" id="english-marks" name="english" required min="0" max="100"
class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded-lg focus:outline-none focus:border-blue-500 transition-all duration-300"
placeholder="78">
<div class="absolute inset-0 rounded-lg pointer-events-none input-highlight hidden"></div>
</div>
</div>
</div>
<div class="flex justify-end space-x-4 mt-6">
<button type="button" id="add-student"
class="px-6 py-2 border border-blue-500 rounded-lg shadow-sm text-sm font-medium text-blue-500 hover:bg-blue-500/10 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-all duration-300">
Add Student
</button>
<button type="button" id="export-excel"
class="px-6 py-2 border border-transparent rounded-lg shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-all duration-300">
Export to Excel
</button>
<button type="reset"
class="px-6 py-2 border border-gray-500 rounded-lg shadow-sm text-sm font-medium text-gray-300 hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-500 transition-all duration-300">
Clear
</button>
</div>
</form>
<div class="mt-8">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-300">Student Records</h2>
<span id="student-count" class="text-sm text-gray-400">0 students</span>
</div>
<div class="overflow-x-auto">
<table id="student-table" class="min-w-full divide-y divide-gray-700">
<thead class="bg-gray-700">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">ID</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Age</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Address</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Math</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Science</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">English</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Total</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="student-table-body" class="bg-gray-800 divide-y divide-gray-700">
<!-- Student records will be added here -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
// Initialize Feather Icons
feather.replace();
// Student data array
let students = [];
// Input highlight animation
document.querySelectorAll('input, textarea').forEach(input => {
input.addEventListener('focus', function() {
this.parentElement.querySelector('.input-highlight')?.classList.remove('hidden');
});
input.addEventListener('blur', function() {
this.parentElement.querySelector('.input-highlight')?.classList.add('hidden');
});
});
// Add student to table
document.getElementById('add-student').addEventListener('click', function() {
const form = document.getElementById('studentForm');
const name = document.getElementById('student-name').value.trim();
const id = document.getElementById('student-id').value.trim();
const age = parseInt(document.getElementById('student-age').value);
const address = document.getElementById('student-address').value.trim();
const math = parseInt(document.getElementById('math-marks').value);
const science = parseInt(document.getElementById('science-marks').value);
const english = parseInt(document.getElementById('english-marks').value);
// Validation
if (!name || !id || !age || !address || isNaN(math) || isNaN(science) || isNaN(english)) {
alert('Please fill all fields correctly');
return;
}
if (name.length < 3) {
alert('Name must be at least 3 characters');
return;
}
if (age < 5 || age > 25) {
alert('Age must be between 5 and 25');
return;
}
if ([math, science, english].some(mark => mark < 0 || mark > 100)) {
alert('Marks must be between 0 and 100');
return;
}
// Check for duplicate ID
if (students.some(s => s.id === id)) {
alert('Student ID already exists');
return;
}
// Create student object
const student = { name, id, age, address, math, science, english };
// Add to array
students.push(student);
// Add to table
addStudentToTable(student);
// Reset form
form.reset();
// Show success message
showNotification('Student added successfully', 'success');
});
// Add student to table function
function addStudentToTable(student) {
const tableBody = document.getElementById('student-table-body');
const row = document.createElement('tr');
row.className = 'hover:bg-gray-700 transition-colors duration-200';
row.dataset.id = student.id;
const totalMarks = student.math + student.science + student.english;
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${student.name}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${student.id}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${student.age}</td>
<td class="px-6 py-4 text-sm text-gray-300">${student.address}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${student.math}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${student.science}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${student.english}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">${totalMarks}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">
<button type="button" class="text-red-500 hover:text-red-400 delete-btn" onclick="deleteStudent('${student.id}', this)">
<i data-feather="trash-2" class="w-4 h-4"></i>
</button>
</td>
`;
tableBody.appendChild(row);
feather.replace();
// Update student count
document.getElementById('student-count').textContent = `${students.length} students`;
}
// Global delete function
function deleteStudent(studentId, btn) {
students = students.filter(s => s.id !== studentId);
btn.closest('tr').remove();
showNotification('Student deleted successfully', 'info');
// Update student count
document.getElementById('student-count').textContent = `${students.length} students`;
}
// Export to Excel
document.getElementById('export-excel').addEventListener('click', function() {
if (students.length === 0) {
alert('No student data to export');
return;
}
try {
// Prepare worksheet
const ws = XLSX.utils.json_to_sheet(students.map(student => ({
'Name': student.name,
'Student ID': student.id,
'Age': student.age,
'Address': student.address,
'Math Marks': student.math,
'Science Marks': student.science,
'English Marks': student.english,
'Total Marks': student.math + student.science + student.english,
'Average': ((student.math + student.science + student.english) / 3).toFixed(2)
})));
// Create workbook
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Students");
// Generate timestamp
const timestamp = new Date().toISOString().split('T')[0];
// Export to Excel
XLSX.writeFile(wb, `student_data_${timestamp}.xlsx`);
showNotification('Excel file exported successfully', 'success');
} catch (error) {
console.error('Export error:', error);
alert('Failed to export data. Please try again.');
}
});
// Notification system
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg z-50 transition-all duration-300 ${
type === 'success' ? 'bg-green-600' : type === 'error' ? 'bg-red-600' : 'bg-blue-600'
} text-white`;
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.opacity = '0';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
// Load sample data
document.addEventListener('DOMContentLoaded', function() {
// Add some sample data
const sampleStudents = [
{ name: 'Alice Johnson', id: 'S001', age: 18, address: '123 Main St, City', math: 85, science: 90, english: 78 },
{ name: 'Bob Smith', id: 'S002', age: 19, address: '456 Oak Ave, Town', math: 92, science: 88, english: 85 }
];
sampleStudents.forEach(student => {
students.push(student);
addStudentToTable(student);
});
// Initialize student count
document.getElementById('student-count').textContent = `${students.length} students`;
});
</script>
</body>
</html>