0

Does anyone know how to use an array in html to compare the elements of the array without using php?

This is what i have tried:

<form/>

<script language="javascript">

function check(form) {

var users = new Array();
    users[0] = "John";
    users[1] = "Ricky";
    users[2] = "Billy";
    users[3] = "Sunny";

var pass = new Array();
    pass[0] = "123456";
    pass[1] = "password";
    pass[2] = "light";
    pass[3] = "nero";

for (int i = 0; i < users.length; i++)
    {
    if (users[i] == pass[i])
    {
    window.open('http://ntm023.x10.mx/slotgame.html');
    }
        else
        {
        window.alert("error in username or password");
        }
    }

I want to compare these two arrays without using php.

Grzegorz Adam Kowalski
  • 5,243
  • 3
  • 29
  • 40
  • 1
    I assume you mean with Javascript, not HTML, right? – Dave Nov 19 '13 at 21:59
  • What is your exact problem? – gearsdigital Nov 19 '13 at 21:59
  • Yeah javascript, I am trying to get a login page to compare a given set of usernames and passwords. So if the username and password matches it moves onto a different webpage. So as the for loop begins to go through the first array when the index matches then the user can move foreward – user3010764 Nov 19 '13 at 22:07
  • For example how I wanted it to go is say if a user enter the username "Ricky" and his password is "password" yet he entered nero there is a pop-up saying "error in username or password" otherwise entering his own password moves the user to the next page. – user3010764 Nov 19 '13 at 22:22
  • Yes, well, you're on the right track with the Javascript code; all you need to do is remove the alert from the loop and put it underneath, after the loop ends. (The same program logic as with PHP.) And of course, compare users[i] to the actually entered username, but that would be the same as in PHP too. – Mr Lister Nov 20 '13 at 09:25

0 Answers0