JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Password Element

Name

Password Element---input field for sensitive data

Availability

Navigator 2.0, Internet Explorer 3.0; enhanced in Navigator 3.0

Synopsis

form.name
form.elements[i]

Properties

defaultValue

A read-only string that specifies the initial value to appear in the password input field. This property is specified by the VALUE attribute of the HTML tag that created the Password element.

form

A read-only reference to the Form object that contains the Password element.

name

A read-only string, set by the HTML NAME attribute, that specifies the name of the Password element. This is also the name that can be used to reference the Password element as a property of its form.

type

A read-only string that specifies the type of this form element. For Password elements, it has the value "password". Available in Navigator 3.0 and later.

value

In Navigator 3.0, with the data-tainting security model enabled, this property is a read-only string that specifies the password value entered by the user. In Navigator 2.0, and in 3.0 without data tainting enabled, this property exists, but always contains the empty string.

Methods

blur()

Remove the keyboard focus from the Password element.

focus()

Set the keyboard focus to the Password element. When focus is set, all keystrokes are automatically entered into this element.

select()

Highlight all the text in the Password element, and enter a special mode so that future input replaces the highlighted text.

Event Handlers

onblur()

Invoked when a user action causes the Password element to lose the keyboard focus.

onchange()

Invoked when the user changes the value in the Password element and moves the keyboard focus elsewhere. This event handler is not invoked for every keystroke in the Password element, but only when the user completes an edit.

onfocus()

Invoked when a user action causes the Password element to gain the keyboard focus.

HTML Syntax

A Password element is created with a standard HTML <INPUT> tag:

<FORM>
    ...
  <INPUT
    TYPE="password" specifies that this is a Password element
    [ NAME="name" ]   a name that can later be used to refer to this element
    specifies the name property
    [ VALUE="default" ]   the default value transmitted when the form is submitted
    [ SIZE=integer ]  how many characters wide the element is
  >
    ...
</FORM>

Description

The Password element is a text input field intended for input of sensitive data, such as passwords. As the user types characters, only asterisks appear, so that the input value cannot be read by a bystander looking over the user's shoulder.

As an additional security precaution, JavaScript cannot read the value typed by the user either. The value property is a read-only string that initially contains the value specified by the VALUE attribute. The user's input is transmitted to the server when the form is submitted, but that input does not appear in this property. Setting this property has no effect on the value transmitted. The VALUE attribute specifies the data to be transmitted if the user does not type anything, and this default value is the only thing to which JavaScript has access.

See Also

"Element", "Form", "Text"


Previous Home Next
parseInt() Book Index Password.blur()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
This HTML Help has been published using the chm2web software.