... the function returns true because the form is executing. What to do to make it do nothing if I close / cancel poppup?
It all depends on how you call your function reason, but if you want it to reasonreturn falsewhen promptcanceled, then:
function reason(id) {
var reason = prompt("State reason");
while (reason !== null && !reason.trim()) {
reason = prompt("Please enter text");
}
if (reason === null) {
return false;
}
document.getElementById(id).value = reason;
return true;
}
promptreturns nullwhen canceled.
, , reason, - true false.
: , . , ...