MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / getLocationInfo

Function getLocationInfo

assets/js/PinCodeSearch.js:4–54  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

2document.querySelector('body').addEventListener('click', deleteLocation)
3
4function getLocationInfo(e) {
5 const zip = document.querySelector('.input').value
6 console.log(zip);
7
8 fetch(`https://api.postalpincode.in/pincode/${zip}`)
9 .then(response => {
10 console.log(response);
11 console.log(response.status);
12 return response.json()
13 })
14 .then(data => {
15 console.log(data);
16 let output = "";
17 if(data[0].PostOffice == null) {
18 console.log("Hello");
19 showIcon("remove")
20 document.querySelector("#output").innerHTML = `
21 <article class="message is-danger">
22 <div class="message-body">Invalid Zipcode, please try again</div></article>`
23 } else {
24 showIcon('check')
25 data[0].PostOffice.forEach((post) => {
26 console.log(post);
27 output += `
28 <article class="message is-secondary is-dark">
29 <div class="message-header ">
30 <p><i class="fa fa-map-pin"></i> &nbsp; Location Info</p>
31 <button class="delete"></button>
32 </div>
33 <div class="message-body mbody">
34 <ul>
35 <li><strong>Name : &nbsp; </strong>${post.Name}</li>
36 <li><strong>BranchType : &nbsp; </strong>${post.BranchType}</li>
37 <li><strong>DeliveryStatus : &nbsp; </strong>${post.DeliveryStatus}</li>
38 <li><strong>Circle : &nbsp; </strong>${post.Circle}</li>
39 <li><strong>District : &nbsp; </strong>${post.District}</li>
40 <li><strong>Division : &nbsp; </strong>${post.Division}</li>
41 <li><strong>Region : &nbsp; </strong>${post.Region}</li>
42 <li><strong>State : &nbsp; </strong>${post.State}</li>
43 <li><strong>Country : &nbsp; </strong>${post.Country}</li>
44 </ul>
45 </div>
46 </article>
47 `
48 })
49 document.querySelector('#output').innerHTML = output
50 }
51 })
52
53 e.preventDefault()
54}
55
56function showIcon(icon) {
57 document.querySelector('.icon-remove').style.display = 'none'

Callers

nothing calls this directly

Calls 1

showIconFunction · 0.85

Tested by

no test coverage detected