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

  • SEARCH
  • Home
  • 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 605537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:09:24+00:00 2026-05-13T17:09:24+00:00

I’m new to javascript/ajax and a bit stuck right now. The assignment is to

  • 0

I’m new to javascript/ajax and a bit stuck right now.
The assignment is to use only javascript/ajax.

I’m supposed to make a login-form, and when typing in the right password it will display a “secret message”. Currently this message is an alert-box.

This is in the script for validating the form input:

var riktigPassord = 'password';     
var passord = window.document.passordSkjema.passord.value;
     if (passord == riktigPassord ) {
      alert("Dette er en hemmelig beskjed");
      window.document.passordSkjema.passord.focus();
      return true;
     }
     else {
      alert("Innlogging mislyktes. Passord er feil!");
      window.document.passordSkjema.passord.focus();
      return false;
     }
    }//slutt på funksjonen her

And this is the code for the form:

<form name="passordSkjema" action="#" method="post" 
onSubmit="return validerPassord();">
Passord: <input type="text" name="passord"><br>
<input type="submit" name="knapp">
</form>

I’m supposed to get the password from a txt-file. (still using only javascript)
and in my case, the txt-filename is “password.txt”.

I’ve never done this before, but I think I know how to make a XHR-object… xD

// New XMLHttpRequest-object
function newXHRobjekt() {
 try {
  XHRobjekt = new XMLHttpRequest(); // Firefox, Opera, ...
 } catch(err1) {
  try {
   XHRobjekt = new ActiveXObject("Microsoft.XMLHTTP"); // Noen IE
  } catch(err2) {
   try {
    XHRobjekt = new ActiveXObject("Msxml2.XMLHTTP"); // Noen IE
   } catch(err3) {
    XHRobjekt = false;
   }
  }
 }
 return XHRobjekt;
}

So.. My question is. How do I use a XHR-object to get use the functions above to check the password-input against password.txt. the file only contains the password (for instance only “12345”). and also I would like to know how to get the “secret message” from another txt-file.

I’m aware that this isn’t secure at all, but it’s a part of understanding javascript/Ajax, in my classes.

Thanks!

  • 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-13T17:09:24+00:00Added an answer on May 13, 2026 at 5:09 pm

    add the following code to the onload event of the body.

    var passwordLoaded = false;
    var password = "";
    var secretMessageLoaded = false;
    var secretMessage = "";
    
    var xhr = newXHRobjekt();
    xhr.open("GET", "password.txt");
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            password = xhr.responseText;
            passwordLoaded = true;
        }
    }
    xhr.send(null);
    
    xhr = newXHRobjekt();
    xhr.open("GET", "secret_message.txt");
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            secretMessage = xhr.responseText;
            secretMessageLoaded = true;
        }
    }
    xhr.send(null);
    

    If both passwordLoaded and secretMessageLoaded are set to true you can use the variables password and secretMessage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.