-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
57 lines (52 loc) · 1.92 KB
/
script.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
45
46
47
48
49
50
51
52
53
54
55
56
57
let input = document.getElementById("inputBox")
let result = document.getElementById("result")
function cls() {
result.innerHTML = " ";
input.value = " ";
}
let h2 = document.createElement('h2');
function search() {
let a = input.value;
a = a.length;
console.log(a);
if(a==6) {
a = input.value;
let url = "https://api.postalpincode.in/pincode/"+ a;
let p = fetch(url);
p.then((response)=>{
return response.json();
}).then((value)=>{
console.log(value);
ihtml = "";
for(item in value) {
item += `
// <h2>Block = ${value[item].PostOffice[0].Block}<h2>
<h2>BranchType = ${value[item].PostOffice[0].BranchType}<h2>
<h2>Circle = ${value[item].PostOffice[0].Circle}<h2>
<h2>Country = ${value[item].PostOffice[0].Country}<h2>
<h2>DeliveryStatus = ${value[item].PostOffice[0].DeliveryStatus}<h2>
<h2>District = ${value[item].PostOffice[0].District}<h2>
<h2>Division = ${value[item].PostOffice[0].Division}<h2>
<h2>Name = ${value[item].PostOffice[0].Name}<h2>
<h2>PinCode = ${value[item].PostOffice[0].PinCode}<h2>
<h2>Region = ${value[item].PostOffice[0].Region}<h2>
<h2>State = ${value[item].PostOffice[0].State}<h2>
`
}
result.innerHTML = item;
}).catch((error)=>{
result.innerHTML = "Enter valid pincode, data not found";
})
}
else {
h2.innerHTML = "Invalid Pincode";
result.innerHTML = h2.innerText;
input.value = "";
setTimeout(()=>{
clear();
},2000);
}
}
function clear() {
result.innerText = "";
}