HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/Eurotools/euro-tools.nl/resources/assets/js/shop/vatCheck.js
var vatCheck = {
    check: function (vatCode) {
        console.log('checking vat: '+vatCode);

        return axios.post('/validateVat', {
            company_vat_number: vatCode,
        })
    }
};

document.addEventListener("DOMContentLoaded", function() {
    var inputField = document.getElementById('company_vat_number');
    if(!inputField) return;

    inputField.addEventListener('change', function() {
        var checkPromise = vatCheck.check(inputField.value);
        checkPromise.then(function(response) {
            console.log(response);
            if(response.data === true)
            {
                console.log('vat is valid');
                inputField.classList.remove('invalid');
                inputField.classList.add('valid');
            } else {
                console.log('vat is not valid');
                inputField.classList.remove('valid');
                inputField.classList.add('invalid');
            }
        }).catch(function(error) {
            console.log('Vat check error');
            console.error(error);
        });
    });
});