W3Schools.com

Password readOnly Property

Password Object Reference Password Object

Definition and Usage

The readOnly property sets or returns whether a password field is read-only, or not.

A read-only field cannot be modified. However, a user can tab to it, highlight it, and copy the text from it.

Tip: To prevent the user from interacting with the field, use the disabled property instead.

Syntax

Set the readOnly property:

passwordObject.readOnly=true|false

Return the readOnly property:

passwordObject.readOnly


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The readOnly property is supported in all major browsers.


Example

Example

Set a password field to be read-only:

<html>
<head>
<script type="text/javascript">
function setResult()
{
document.getElementById("pwd").readOnly=true;
}
</script>
</head>
<body>

<form>
Password: <input type="password" id="pwd" />
</form>

<button type="button" onclick="setResult()">Set read-only</button>

</body>
</html> 

Try it yourself »


Password Object Reference Password Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE