In the following code, on successful login, I am trying to open admin.htm. the content is loaded into the same page using AJAX, how can I instead open it in a new window but retain any error messages in the original window in case of error?
login.htm
<form>
Username:<input type="text" name= "username" size="15" />
Password:<input type="password" name= "passwrd" size="15" />
<input name="submit" type = "button" onClick = "getdata('login.php','display',username.value,passwrd.value)" value = "Login" />
</form>
<div id="display"></div>
login.js
function getdata(dataSource, divID, usrname, pwd) {
if (xhr) {
var obj = document.getElementById(divID);
var requestbody = "username=" + encodeURIComponent(usrname) + "&password=" + encodeURIComponent(pwd);
xhr.open("POST", dataSource, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
obj.innerHTML = xhr.responseText;
}
}
xhr.send(requestbody);
}
}
the form is using AJAX on purpose to display the result on the page you are on…
To open the result in a new page, remove the onclick and the script and give a target:
If all you want is to NOT see the form after submit, wrap the form in the display div:
UPDATE: