View Full Version : Help with Javascript arrays & parallel arrays

06-24-2008, 06:30 AM
Hi there, I urgently need to find a solution to the following problem. I need to add some scripting so the system will do the following:

Request the user's name!
If what is entered matches the data held then you are prompted to enter a password.
If this value matches as well then you receive a message saying "Welcome".
If the username is incorrect then a message appears saying "Unknown name".
If the password is incorrect then a message appears saying "Invalid password".

It has been suggested that the variable readerIndex can be used to store the index number of the logged-in reader in the three arrays of information. Negative value (e.g. -1) can represent the fact no reader has successfully logged in.

I have made a start on the script, but what is really holding me back is getting the program to cross-check the username. I would really appreciate any guidance. The script is below:




var readerIndex;

// Array Of Titles

var bookArray = ['Book 1', 'Book 2', 'Book 3', 'Book 4', 'Book 5', 'Book 6'];

// Array Of Authors

var authorArray = ['Author 1', 'Author 2', 'Author 3', 'Author 4', 'Author 5', 'Author 6'];

// Array Of Book Borrowing Information

var borrowedArray = ['-', '-', '-', 'rs-14', '-', '-'];

// Array Of Book Reservation Information

var reservedArray = ['-', 'ly-44', '-', '-', '-', '-'];

// Array Of Restrictions On Books

var restrictionArray = ['g', 'r', 'g', 'g', 'r', 'g'];

// Array Of Readers

var readerNameArray = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff'];

// Array Of Reader Ages

var readerAgeArray = [21, 10, 15, 62, 41, 32];

// Array Of Reader Passwords

var readerPasswordArray = ['zzz', 'yyy', 'vvv', 'www', 'ttt', 'ppp'];

for (var count = 0; count < readerNameArray.length; count = count + 1)
window.prompt('Please enter your reader name');
if (count != readerNameArray[count])
document.write('<BR>' + 'Test')
document.write('<BR>' + '====')
document.write('<BR>' + 'Welcome')
document.write('<BR>' + 'Test')
document.write('<BR>' + '====')
document.write('<BR>' + 'Unknown name')