forked from sonaliirawat/Training-Lectures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment1 (1).html
92 lines (80 loc) · 3.02 KB
/
assignment1 (1).html
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
<!DOCTYPE html>
<html>
<head>
<link href="bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Form</h1>
<div class="row mb-2">
<div class="col-md-12">
<div class="card">
<div class="card-header">
Add Student
</div>
<div class="card-body">
<div class="form-group">
<label for="email">Student Name:</label>
<input type="text" class="form-control" id="txtStudentName">
</div>
<div class="form-group">
<label for="email">Student Age:</label>
<input type="number" min="0" max="110" class="form-control" id="txtStudentAge">
</div>
<input type="button" value="Add Student to List" class="btn btn-primary mt-1"
id="btnAddStudent">
<input type="button" value="Clear Students" class="btn btn-danger mt-1" id="btnClearStudents">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12" id="dvStudentList">
<table class="table table-bordered" id="tblStudentList">
<thead>
<tr>
<th>Student Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<script src="jquery-3.6.0.min.js"></script>
<script>
$(document).ready(() => {
//var students = ["Stu 1", "Stu 2", "Stu 3", "Stu 4", "Stu 5", "Stu 6", "Stu 7", "Stu 8", "Stu 9", "Stu 10", "Stu 11", "Stu 12"];
var students = [
{
name: "Stu 1",
age: 18
},
{
name: "Stu 2",
age: 19
},
{
name: "Stu 3",
age: 20
}
];
students.forEach(element => {
$("#tblStudentList").find('tbody').append("<tr><td>" + element.name + "</td><td>" + element.age + "</td></tr>");
});
$("#btnAddStudent").click(function () {
var studentName = $("#txtStudentName").val();
var studentAge = $("#txtStudentAge").val();
$("#tblStudentList").find('tbody').append("<tr><td>" + studentName + "</td><td>" + studentAge + "</td></tr>");
$('#txtStudentName').val('').focus();
$('#txtStudentAge').val('');
})
$("#btnClearStudents").click(function () {
$('#tblStudentList').find('tbody').html('');
});
})
</script>
</body>
</html>