Of course when we have form elements in a script, we start with them so we can understand the hierarchy statements in the functions.
<FORM NAME="userInput">
<INPUT TYPE="text" Name ="u1" SIZE="2">
<INPUT TYPE="text" Name ="u2" SIZE="2">
<INPUT TYPE="text" Name ="u3" SIZE="2">
<INPUT TYPE="button" VALUE="Enter" onClick="GoIn()">
</FORM>
The form itself is given the name "userInput". Following the form flag are three input text boxes, each set to accept only two characters.
The text boxes are named "u1" "u2" and "u3" down the line.
A final button triggers a function called GoIn(). Now we can put together hierarchy statement to grab whatever the user puts into the boxes. Now the GoIn() function:
function GoIn()
{
var Password = new Array("p","j","l","z","o","e","m","b","x","z")
The function starts with an array. We've used the format before. The array is named "Password". Each element in the array is a text string because it is contained within double quotes. A comma separates each item, with no spaces.
What isn't shown here is what helps us to use the script as a password function. Any time you set up an array in JavaScript, the array list members are given numbers starting at zero and counting up until JavaScript runs out of things to count.
In this case, "p" is zero, "j" is one, "l" is three, and so forth. That will become important in a moment.
function getNumbers()
{
return document.userInput.u1.value
return document.userInput.u2.value
return document.userInput.u3.value
}
Next, a second function, getNumbers(), is employed to simply return, to the script,
the numbers the user put into the text boxes. Note that the three hierarchy statements are each attached to one of the three text boxes.
var input1 = document.userInput.u1.value
var input2 = document.userInput.u2.value
var input3 = document.userInput.u3.value
Next, the three input items that are returned from the three text boxes are given the variable names
"input1", "input2", and "input3". Please remember when grabbing values from form elements, the use of the command "value" is very important at the end of the hierarchy statement.
var pw1 = Password[input1]
var pw2 = Password[input2]
var pw3 = Password[input3]
Here the array is called upon three times ("Password" is the name assigned to the array, remember?). The array items pulled out will be equal to the three numbers entered by the user. Notice that each time, the variable names assigned to the user's choices are used within square brackets.
This format works basically like a replacement. Whatever number the user put in will replace the variable name. So if the user put zero in the first box, "input1" will be replaced by zero and the first letter of the array, "p", will be returned. That happens three times, assigning the variables "pw1", "pw2", and "pw3", for each of the text boxes.
var pw = pw1 + pw2 + pw3
if (pw == pw1+pw2+pw3)
{location.href = pw+ ".html"}
}
Last but not least, the variable "pw" is created and given the value of the three variables put together.
An If statement asks if "pw" is equal to pw1+pw2+pw3. Of course it is. We just set it to that.
Since it is, then the commands location.href trigger, taking the user to the page name created by the user's three numbers plus .html.
Do that again...