Reputation: 5
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>
Upvotes: 0
Views: 59
Reputation:
Two reasons:
<head></head>
tags<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.
Upvotes: 1
Reputation: 96
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
Upvotes: 1