This function returns a Promise.
async function validateStudent(event, reg, pass) {
if (reg != '' || pass != '') {
var res = await requestStudent(reg, pass);
if (res == null) {
document.getElementById("error").innerText = "Invalid username or password.";
return false;
}
else {
document.getElementById("HiddenField1").value = res;
return true;
}
}
else {
document.getElementById("error").innerText = "Please fill in the form.";
return false;
}
}
If I want to use this as an event handler, how will I get its true value without using another async function in the onclick attribute? I want to use this function like this:
<button onclick="return validateStudent('abc', '123')">Send</button>
I tried using return Promise.resolve(validateStudent('abc', '123')), it did not work.