0

Hello I am making a login website and i just want to have the javascript with the password and username in an different file just to make it a little bit harder to find(its just a school project). But my problem is that it wont verify and redirect to my Main.html code after you click the login button.

As you can see in the code i have tried to connect it with the code.

<script src="Login.js"></script>

Here is the html code:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
      <meta charset="utf-8">
      <title>kjedelig AF</title>
      <link rel="stylesheet" href="Login.css">
  </head>
  <body oncontextmenu="return false;">

<form class="box" action="Login.html" method="post" name="login">
  <div class="login">
    <h1>Kjedelig AF</h1>
    <input type="text" name="usrname" placeholder="Username">
    <input type="password" name="pswrd" placeholder="Password">
    <input type="submit" onclick="return check(this.form)" value="Login">
  </div>
</form>
<script src="Login.js"></script>
  </body>
</html>

And here is my javascript code witch i have problems connecting to the html code:

<script language="javascript">
  function check(form){
    if(form.usrname.value == "dd" && form.pswrd.value == "dd")  {
    window.location.href= "Main.html";
    return false;
    }
    else
    {
    alert("Iks dette er kjedelig AF :)")
    }
    return true;
    }
</script>
1
  • From your posted example you have HTML in your login js, which shouldn't be there if its a js file. Commented Mar 31, 2019 at 16:56

2 Answers 2

1

First of all, include your JS file at the <head>. there is no good reason not to.

To fix your issue remove <script language="javascript"></script> from your .js file

you should use <script language="javascript"></script> when inside .html file not .js

Sign up to request clarification or add additional context in comments.

Comments

1

Two reasons:

  1. The script link to the JS file should be anywhere within the <head></head> tags
  2. The JS file shouldn't have the <script language="javascript"></script>, all that the JS file needs to have is:
function check(form){
    if(form.usrname.value == "dd" && form.pswrd.value == "dd")  {
    window.location.href= "Main.html";
    return false;
    }
    else
    {
    alert("Iks dette er kjedelig AF :)")
    }
    return true;
}

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.