Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Postnummer autofill - Henter postnummer fra bring og autofiller en form input med det
<input type="text" pattern="\d*" class="form-control" id="postal" placeholder="0000" maxlength="4" required onkeyup="autofillCity(this.value)">
function autofillCity(postnummer) {
if (postnummer.length == 4) {
$.ajax({
url: 'https://api.bring.com/shippingguide/api/postalCode.json?clientUrl=https://alfawiz.kolsrudweb.no/kunde/ny&pnr=' + postnummer + '',
method: 'get',
dataType: 'json',
crossDomain: true,
success: function(data) {
if (data.valid == true) {
document.getElementById("city").value = data.result;
return true;
} else {
document.getElementById("city").value = "Ugyldig postnummer";
return false;
}
}
});
} else {
document.getElementById("city").value = "Skriv inn postnummer...";
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.