Hello Everyone,
I have no knowledge of coding and thatswhy I took a plan on wix. I am building a website for my business on wix editor. I have made a form and i want that when a user enters pin code, fields like area, city and district should auto fill. I have the api for India but i dont know how to do it. I mean how should I put it? Please help me. My website is www.bankshub.in. It is not published yet. Please understand that i have absolutely no knowledge of coding. Thanks and Regards.
What API are you using? Perhaps a link to the API documentation would help.
I have created a test site that shows it working. Check it out: https://preztech.wixstudio.io/test/pincode
Here’s the code:
import { getJSON } from 'wix-fetch';
const url = "https://api.postalpincode.in/pincode/";
$w.onReady(function () {
});
export function button1_click(event) {
if ($w('#pincode')) {
let pin = $w("#pincode").value;
let fullUrl = `${url}${pin}`;
$w('#link').text = fullUrl;
$w('#status').text = "FETCHING...";
getJSON(fullUrl)
.then(json => {
if (json[0].Status == "Success") {
$w('#status').text = json[0].Status;
$w("#area").value = json[0].PostOffice[0].Name;
$w("#city").value = json[0].PostOffice[0].Region;
$w("#district").value = json[0].PostOffice[0].District;
} else {
$w('#status').text = "ERROR";
$w("#area").value = "";
$w("#city").value = "";
$w("#district").value = "";
}
})
}
}
I have dropped you a message, check it out: