Hi all,
The below code is my event listener for submit button. I am calling an API in the below code and when the call is successful it should forward to the next page when I return a true at the end of the function. But it does not forward. If I remove the event handler it works. I need to execute this API in order to validate the serviceable zip code.
Any input in this regard is appreciated.
var submitButton = document.querySelector(’#lp-pom-button-198’);
submitButton.addEventListener(‘click’, async (e) => {
let address = document.querySelector(‘input#autocomplete’);
let zip = document.querySelector(‘input#postal_code’);
let category = document.querySelector(‘input#button_selected’);if (zip.value === '') { return false; } if (address.value === '' && zip.value !== '') { alert('address = blank'); zip.value = ''; return false; } // all good, call hunksWare api to verify zip code //alert('You zip code is ' + zip.value);
let bearer = ‘Bearer xyzdfsadfdasjfdfadfdasafdfadsjfdsaj’;
let payload = {
“postal”: zip.value,
“job_category_id”: category.value,
};submitButton.innerText = 'Working ...'; submitButton.disabled = true; let response = await fetch('https://api.chhj.com/rest/v1/servicecheck', { method: 'post', headers: { 'Authorization': bearer, }, body: JSON.stringify(payload) }); let json = await response.json(); alert('Zip code: ' + zip.value + ', status: ' + json.meta.status.description); submitButton.innerText = "Verify Address"; submitButton.disabled = false; if (json.meta.status.id === 404) { alert("Sorry, We do not Serve this locaiton"); return false; } return true;
});