Password
A text field on an HTML form that conceals its value by displaying asterisks (*). When the user enters text into the field, asterisks (*) hide entries from view.
JavaScript 1.1: added |
Created by
The HTMLINPUT tag, with "password" as the value of the TYPE attribute. For a given form, the JavaScript runtime engine creates appropriate Password objects and puts these objects in the elements array of the corresponding Form object. You access a Password object by indexing this array. You can index the array either by number or, if supplied, by using the value of the NAME attribute.
Event handlers
Description
APassword object on a form looks as follows:
Password object is a form element and must be defined within a FORM tag.
Security
JavaScript versions 1.2 and later. Thevalue property is returned in plain text and has no security associated with it. Take care when using this property, and avoid storing its value in a cookie.
JavaScript 1.1.
If a user interactively modifies the value in a password field, you cannot evaluate it accurately unless data tainting is enabled. For information on data tainting, see the Client-Side JavaScript Guide.
Property Summary
| Property |
Description
|
|
|
|
| |
|---|
Method Summary
| Method |
Description
|
|
|
| |
|---|
watch and unwatch methods from Object.
Examples
The following example creates aPassword object with no default value:
<B>Password:</B>
<INPUT TYPE="password" NAME="password" VALUE="" SIZE=25>
See also
Form, Text
blur
Removes focus from the object.Syntax
blur()
Parameters
NoneExamples
The following example removes focus from the password elementuserPass:
userPass.blur()This example assumes that the password is defined as
<INPUT TYPE="password" NAME="userPass">
See also
Password.focus, Password.select
defaultValue
A string indicating the default value of aPassword object.Security
JavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.Description
The initial value ofdefaultValue is null (for security reasons), regardless of the value of the VALUE attribute.
Setting defaultValue programmatically overrides the initial setting. If you programmatically set defaultValue for the Password object and then evaluate it, JavaScript returns the current value.
You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property.
See also
Password.value
focus
Gives focus to the password object.Syntax
focus()
Parameters
NoneDescription
Use thefocus method to navigate to the password field and give it focus. You can then either programmatically enter a value in the field or let the user enter a value.
Examples
In the following example, thecheckPassword function confirms that a user has entered a valid password. If the password is not valid, the focus method returns focus to the Password object and the select method highlights it so the user can reenter the password.
function checkPassword(userPass) {This example assumes that the
if (badPassword) {
alert("Please enter your password again.")
userPass.focus()
userPass.select()
}
}
Password object is defined as
<INPUT TYPE="password" NAME="userPass">
See also
Password.blur, Password.select
form
An object reference specifying the form containing this object.Description
Each form element has aform property that is a reference to the element's parent form. This property is especially useful in event handlers, where you might need to refer to another element on the current form.
handleEvent
Invokes the handler for the specified event.Syntax
handleEvent(event)
Parameters
event | The name of an event for which the object has an event handler. |
Description
For information on handling events, see the Client-Side JavaScript Guide.name
A string specifying the name of this object.Security
JavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.Description
Thename property initially reflects the value of the NAME attribute. Changing the name property overrides this setting. The name property is not displayed on-screen; it is used to refer to the objects programmatically.
If multiple objects on the same form have the same NAME attribute, an array of the given name is created automatically. Each element in the array represents an individual Form object. Elements are indexed in source order starting at 0. For example, if two Text elements and a Password element on the same form have their NAME attribute set to "myField", an array with the elements myField[0], myField[1], and myField[2] is created. You need to be aware of this situation in your code and know whether myField refers to a single element or to an array of elements.
Examples
In the following example, thevalueGetter function uses a for loop to iterate over the array of elements on the valueTest form. The msgWindow window displays the names of all the elements on the form:
newWindow=window.open("http://home.netscape.com")
function valueGetter() {
var msgWindow=window.open("")
for (var i = 0; i < newWindow.document.valueTest.elements.length; i++) {
msgWindow.document.write(newWindow.document.valueTest.elements[i].name + "<BR>")
}
}
select
Selects the input area of the password field.Syntax
select()
Parameters
NoneDescription
Use theselect method to highlight the input area of the password field. You can use the select method with the focus method to highlight a field and position the cursor for a user response.
Examples
In the following example, thecheckPassword function confirms that a user has entered a valid password. If the password is not valid, the select method highlights the password field and the focus method returns focus to it so the user can reenter the password.
function checkPassword(userPass) {This example assumes that the password is defined as
if (badPassword) {
alert("Please enter your password again.")
userPass.focus()
userPass.select()
}
}
<INPUT TYPE="password" NAME="userPass">
See also
Password.blur, Password.focus
type
For allPassword objects, the value of the type property is "password". This property specifies the form element's type. Examples
The following example writes the value of thetype property for every element on a form.
for (var i = 0; i < document.form1.elements.length; i++) {
document.writeln("<BR>type is " + document.form1.elements[i].type)
}
value
A string that initially reflects theVALUE attribute.Security
JavaScript versions 1.2 and later. This property is returned in plain text and has no security associated with it. Take care when using this property, and avoid storing its value in a cookie. JavaScript 1.1. This property is tainted by default. If you programmatically set thevalue property and then evaluate it, JavaScript returns the current value. If a user interactively modifies the value in the password field, you cannot evaluate it accurately unless data tainting is enabled. For information on data tainting, see the Client-Side JavaScript Guide.
Description
This string is represented by asterisks in thePassword object field. The value of this property changes when a user or a program modifies the field, but the value is always displayed as asterisks.
See also
Password.defaultValue
Table of Contents | Previous | Next | Index
Last Updated: 05/28/99 12:00:09
