-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (27 loc) · 1.17 KB
/
Copy pathscript.js
File metadata and controls
31 lines (27 loc) · 1.17 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
function fetchDetails() {
const pincode = document.getElementById("pincode").value;
fetch(`https://api.postalpincode.in/pincode/${pincode}`)
.then(response => response.json())
.then(data => {
const resultDiv = document.getElementById("result");
if (data[0].Status === "Success") {
const postOffice = data[0].PostOffice.map((postOffice) => {
return `<div id="resultcard">
<h3 class="title"> Pincode Details: ${pincode}</h3><hr>
<h4 class="cityname"> ${postOffice.Name}</h4><br>
<p class="Details"> Branch Type : ${postOffice.BranchType}</p><br>
<p class="Details"> District : ${postOffice.District}</p><br>
<p class="Details"> Block : ${postOffice.Block}</p><br>
<p class="Details"> Region : ${postOffice.Region}</p><br>
<p class="Details"> State : ${postOffice.State}</p><br>
<p class="Details"> Country : ${postOffice.Country}</p><br>
</div>`
})
resultDiv.innerHTML = postOffice.join("");
}
else {
resultDiv.innerHTML = `<p class="Error"> No Details Found for ${pincode}.</p>`;
}
resultDiv.style.display = "block";
}).catch(error => console.error(error));
}