[pass-reset_script] Script now uses a <p> tag under the form instead of alerts or console to show status of message

This commit is contained in:
eoghan.conlon 2023-07-27 18:52:11 +01:00
parent e72f2b2377
commit 51ac57ebf0
2 changed files with 11 additions and 2 deletions

View file

@ -26,11 +26,19 @@ formEl.addEventListener('submit', () => {
fetch('https://reqres.in/api/update', { fetch('https://reqres.in/api/update', {
method: 'POST', method: 'POST',
body: object body: object
}).then(res => console.log(res)).catch(error => console.log(error)); }).then(res => {
if(res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} else if (res.status === 500){
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(error => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
//TODO: Change this to changing a div in html //TODO: Change this to changing a div in html
//alert("Success"); //alert("Success");
} else { } else {
//TODO: Change this to changing a div in html //TODO: Change this to changing a div in html
alert("Failure") document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: new passwords don't match</span>";
} }
}); });

View file

@ -16,6 +16,7 @@
<input type="password" id="newPW2" name="newPWConfirm" /> <br /> <input type="password" id="newPW2" name="newPWConfirm" /> <br />
<input type="Submit" value="Submit" /> <input type="Submit" value="Submit" />
</form> </form>
<p id="formStatus"></p>
<footer> <footer>
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>
</footer> </footer>