-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (43 loc) · 1.44 KB
/
index.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
function pincode() {
var pin = document.getElementById("pincode").value;
var url = `https://api.postalpincode.in/pincode/`;
url+=pin;
var obj='';
fetch(url)
.then(response=>response.json())
.then(data=>{
obj+=`<thead class="thead-dark"><tr>`;
obj+=`<th>S.No</th>`;
obj+=`<th>Name</th>`;
obj+=`<th>BranchType</th>`;
obj+=`<th>Division</th>`;
obj+=`<th>District</th>`;
obj+=`<th>Region</th>`;
obj+=`<th>Circle</th>`;
obj+=`<th>Pincode</th>`;
obj+=`<th>State</th>`;
obj+=`<th>Country</th>`;
obj+=`</tr></thead>`;
for(let i = 0;i<data[0].PostOffice.length;i++)
{
obj+=`<tr>`;
obj+=`<th scope="row">${i+1}</th>`;
obj+=`<td>${data[0].PostOffice[i].Name}</td>`;
obj+=`<td>${data[0].PostOffice[i].BranchType}</td>`;
obj+=`<td>${data[0].PostOffice[i].Division}</td>`;
obj+=`<td>${data[0].PostOffice[i].District}</td>`;
obj+=`<td>${data[0].PostOffice[i].Region}</td>`;
obj+=`<td>${data[0].PostOffice[i].Circle}</td>`;
obj+=`<td>${data[0].PostOffice[i].Pincode}</td>`;
obj+=`<td>${data[0].PostOffice[i].State}</td>`;
obj+=`<td>${data[0].PostOffice[i].Country}</td>`;
obj+=`</tr>`;
}
document.querySelector("#error").innerHTML = "";
document.getElementById("tab").innerHTML = obj;
})
.catch(err=>{
document.getElementById("tab").innerHTML = "";
document.querySelector("#error").innerHTML = "No data found";
})
}