
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input Password value property
The HTML DOM Input password value property is associated with the input element having type=”password” and having the value attribute. This property is used for specifying a default value for password field and it also changes the value to user input.
Syntax
Following is the syntax for −
Setting the value property.
passwordObject.value = text;
Here, text is used for specifying the value for the password field.
Example
Let us look at an example for the input password value property −
<!DOCTYPE html> <html> <body> <h1>Input password Value property</h1> PASSWORD: <input type="password" id="PASS1"> <p>Get the above element value by clicking the below button</p> <button onclick="getValue()">Get Value</button> <p id="Sample"></p> <script> function getValue() { var t = document.getElementById("PASS1").value; document.getElementById("Sample").innerHTML = "The value for the input field is : "+t; } </script> </body> </html>
Output
This will produce the following output −
On typing some text inside the password field and clicking “Get Value” button −
In the above example −
We have created an input field with type password and its id set to “PASS1”.
PHONE NO: <input type="number" value="222" id="NUMBER1">
We have then created the “Get Value” button that will execute the getValue() method when clicked by the user −
<button onclick="getValue()">Get Value</button>
The getValue() method gets the input element by using the getElementById() method and assigns its “value” attribute value to variable t. It will return an empty string if you don’t’ enter anything in the password field before clicking the “Get Value” button. The value attribute change with user input so it will display the current input inside the password field. This variable is then displayed in the paragraph with id “Sample” using its innerHTML property −
function getValue() { var t = document.getElementById("PASS1").value; document.getElementById("Sample").innerHTML = "The value for the input field is : "+t; }
- Related Articles
- HTML DOM Input Password autofocus Property
- HTML DOM Input Password defaultValue Property
- HTML DOM Input Password disabled Property
- HTML DOM Input Password form Property
- HTML DOM Input Password maxLength Property
- HTML DOM Input Password name Property
- HTML DOM Input Password pattern property
- HTML DOM Input Password placeholder property
- HTML DOM Input Password readOnly property
- HTML DOM Input Password required property
- HTML DOM Input Password size property
- HTML DOM Input Password type property
- HTML DOM Input Password object
- HTML DOM Input Time value Property
- HTML DOM Input URL value Property
