const form = document.getElementById("form"); form.addEventListener('submit', formHandler); const form_status = document.getElementById("formStatus"); const button = document.getElementById("button"); button.addEventListener('submit', formHandler); async function formHandler(listener) { listener.preventDefault(); const formData = new FormData(form); const user = formData.get("user"); const pass = formData.get("pass"); const newPW = formData.get("newPW"); if (newPW !== formData.get("newPWConfirm")) { document.getElementById('formStatus').innerHTML = "Failure: new passwords don't match"; return; } const body = {auth: {user: user, pass: pass}, field: "userPassword", value: newPW} let url = 'https://api.account.skynet.ie/ldap/update'; let req; try { req = await fetch(url, { method: 'POST', body: JSON.stringify(body), mode: "cors" }); } catch (e) { form_status.innerHTML = `${e}`; return; } if (req.status !== 200) { form_status.innerHTML = "Failure"; return; } let temp = await req.json(); if (temp.result === 'error') { form_status.innerHTML = `${temp.error}`; } else { form_status.innerHTML = "Success"; } }