-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonstudents.html
47 lines (44 loc) · 1.71 KB
/
jsonstudents.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Student Info by JSON</title>
</head>
<body>
<h1>Displaying Student Data</h1>
<input type="button" onclick="createTable()" value="Show Table" />
<div id="displayInfo"></div>
<script>
function createTable(){
let students=[
{
"name":"Shrivatsa",
"id":"MCA052",
"major":"Computer Netwoks",
"mobile":"9972717789"
},
{
name:"Aravinda S",
id:"MCA015",
major:"SQL",
mobile:"6987256471"
},
{
name:"Sudarma",
id:"MCA087",
major:"Cyber Security",
mobile:"8945213687"
}
]
let tableBody='<table border="8"><tr><th>Student-Name</th><th>Sudent-ID</th><th>Major</th><th>Mob</th></tr>'
students.forEach(function(d){
tableBody+='<tr><td>'+d.name+'</td><td>'+d.id+'</td><td>'+d.major+'</td><td>'+d.mobile+'</td></tr>';
});// +d.name means name will be concatenated as string
tableBody+='</table>';
document.getElementById("displayInfo").innerHTML=tableBody;
};
</script>
</body>
</html>