Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:31:02+00:00 2026-05-25T17:31:02+00:00

In the following code, on successful login, I am trying to open admin.htm. the

  • 0

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);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:31:03+00:00Added an answer on May 25, 2026 at 5:31 pm

    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:

    <form action="login.php" target="_blank" method="post"> 
    Username:<input type="text" name= "username" size="15" /> 
    Password:<input type="password" name= "passwrd" size="15" />
    <input type="submit" value = "Login"  /> 
    </form> 
    

    If all you want is to NOT see the form after submit, wrap the form in the display div:

    <div id="display">
      <form>.....
      </form>
    </div>
    

    UPDATE:

    to get the error message into the page, do 
    
    if (xhr.readyState == 4 && xhr.status == 200) {
      var text = xhr.responseText;
      if (text.indexOf("You must") == 0) obj.innerHTML = text;
      else window.open(text,"_blank")
    }
    
    <?php
    $usernam = $_POST["username"];
    $pwd = $_POST["password"];
    if (empty($usernam) || empty($pwd)) {
        echo "You must enter both username and password to login.";
    } else {
        echo 'admin.htm';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am successfully posting a form via ajax, using the following code; $.post( Page.do?source=ajax,
I'm trying to log onto the following website using HttpWebRequest: http://mostanmeldung.moessinger.at/login.php Texts are in
I'm trying to use the following code to log users in: $(form).submit(function(event) { $.ajax({
Using the following code I am trying to scrape a call log from our
I am successfully instantiating/automating Visual Studio using the following code: System.Type t = System.Type.GetTypeFromProgID(VisualStudio.DTE.9.0);
I'm trying to redirect the user if they login successfully but the code I
I am trying to retrieve this page using curl in php. This page of
The following code is for authenticating to a windows AD server using Java+Kerberos and
I'm using a JScrollPane on a login page, basically after successfull login, it'll go
I am trying to get WWW::Mechanize to login to Yahoo using https; however, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.