javascript to retain form on login failure -
below javascript function authenticate user... wanna retain form on login failure username/password textbox being blank.
function authenticate(form) { if (form.username.value == "administrator" && form.password.value == "password") { window.open('orderlist.aspx')/*opens target page while id & password matches*/ } else { alert("error password or username") $("#username").val("") $("#password").val("") form.????????????('login.aspx')//so stays on same page wihout reloading page. tried window.open, opens instance of form. /*displays error message*/ } }
i assume firing either onclick
or onsubmit
. preventing form submission, want use onsubmit
, have return results of function. in case of validation failure, javascript function needs return false;
prevent form being submitted.
when validation passes, can either return true;
or nothing (assuming want form continue being submitted...if want issue call window.open()
, should return false;
in both cases.
for more detailed explanation, see this answer similar question.
as removing values text fields, have (e.g. below code) work - reason aren't seeing impact page reloading due form being submitted.
$("#username").val(""); $("#password").val("");