0

I have written the following code to validate logins. It will now only check one user ID and password. I want to create a string array to check IDs and passwords but when I try to declare a variable, the function check is reported as not defined.

<html>
  <head>
    <title>Login page</title>
  </head>
  <body>
    <h1 style="font-family:Comic Sans Ms;text-align="center";font-size:20pt color:#00FF00;>Simple Login Page</h1>
    <form name="login">
      Username<input type="text" name="userid"/>
      Password<input type="password" name="pswrd"/>
      <input type="button" onclick="check(this.form)" value="Login"/>
      <input type="reset" value="Cancel"/>
    </form>
    <script language="javascript">
      "use strict"
      function check(form)/*function to check userid & password*/
      {
        int a;
        a = 1;
        if(form.userid.value == "jscholl" && form.pswrd.value == "astronomy")
        {
          window.open("index.html");
        }
        else
        {
          alert("Error Password or Username")/*displays error message*/
        }
      }
    </script>
  </body>
</html>
1
  • The language attribute for script elements was deprecated in HTML 4 and removed in subsequent versions, so omit it. ;-) Commented Aug 15, 2017 at 21:49

2 Answers 2

3

All you have to do is initialize the variable using

var a = 1; or var a; a= 1

NOTE: variables declared in a function can only be accessible by it self or other within its scope

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

Comments

1

This line here

int a;
a = 1;

You just need to do var a = 1 - By default, there is no type assertion in JS.

Comments

Your Answer

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