1

!!!Solved!!!

So I'm pretty new to HTML, CSS and Javascript is near unknown to me. I used the help of people from a previous question, to do it. The code of login was working before, but it doesn't work anymore and I can't really figure out what's the problem as everything for me seems alright. The way it should work, that in (labavakara.neocities.org) you enter 'admin' and 'labadiena' in the form and it sends you to another website of my own.

Anyone know what I did wrong?

function check(form) should see what was entered in the form boxes and then see if it matches the correct user and pass.

When I go to the site and inspect element, then check console - 0 errors.

Code

<!DOCTYPE html>

<html>

<head>


<style>
div {
    height: 200px;
    width: 400px;

    position: fixed;
    top: 50%;
    left: 55%;
    margin-top: -100px;
    margin-left: -200px;
}
body {
 background-image: url("backg.png");
 background-color: #cccccc;
}
function {
  color: red;
}


</style>

<body>


  <script>
function check(form)
{

 if(form.loginInput.value == "admin" && form.passwordInput.value == "labadiena")
  {
    window.location.href = "https://labavakara.neocities.org/trysketuri.html";
  }
 else
 {
   alert("Error Password or Username")
  }
}


  </script>



  <div>
     <title>Login</title>



<form>
        <p><input style="background-color:red;color:black;border:1px solid #ff0000" type="text" id="loginInput" name="login" value="" placeholder="Username"></p>
        <p><input style="background-color:red;color:black;border:1px solid #ff0000" type="password" id="passwordInput" name="password" value="" placeholder="********"></p>
           <a class="submit"><input style="color:blue" type="submit" id="loginbutton" onclick="check(this.form)" name="commit" value="Login"><br>
             <label id="userMessage" style="visibility:hidden;"></label>


</a>

  </form>

    </div>

</body>

</html>


2
  • I hope this goes without saying, but storing the password in plain text in the client-side code is just about the least secure way of logging in. If this is code for school and that's how you were told to do it for this assignment, that's fine, but keep it in mind that logging in and password checking should always be done on the server. Commented Sep 22, 2019 at 16:58
  • @dx_over_dt im fully aware that people can go to inspect element and see it. I'm trying to figure out how to make javascript send an id or a text to a .js file and make that file send back info. Since file types are restricted on neocities if I go free, i'm pretty limited. Commented Sep 23, 2019 at 12:34

1 Answer 1

1

Use type="button" in the input button used for submit form like this

<a class="submit"><input style="color:blue" type="button" id="loginbutton" onclick="check(this.form)" name="commit" value="Login"><br>
         <label id="userMessage" style="visibility:hidden;"></label>

Ref : How to prevent page from reloading after form submit - JQuery

your page is reloaded since you are using type=submit i guess.

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

1 Comment

Please mark the answer as solution by upvoting/clicking the checkmark so others can find it. @ErnesTas

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.