Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q799 Is it possible to have read only text in a text field?

irt.org | Knowledge Base | JavaScript | Form 3.6 | Q799 [ previous next ]

Q799 Is it possible to have read only text in a text field?

Only with browsers that support HTML 4.0, currently Internet Explorer 4+ and Netscape Navigator 6+, with:

<FORM>
<INPUT TYPE="TEXT" VALUE="In HTML 4.0 this should be write protected" READONLY>
</FORM>

You can use JavaScript (in Internet Explorer 4) to set the value of the readOnly attribute:

<SCRIPT LANGUAGE="JavaScript"><!--
function toggle() {
    if (document.all) {
        document.myName.myField.readOnly = !document.myName.myField.readOnly;
     }
}
//--></SCRIPT>

<FORM NAME="myForm">
<INPUT NAME="myField" TYPE="TEXT" VALUE="In HTML 4.0 this should be write protected" READONLY>
<INPUT TYPE="BUTTON" VALUE="Toggle readOnly status" onClick="toggle()">
</FORM>

Take a look at the article at http://www.developer.com/journal/techworkshop/webb2/111798_form.html for more techniques of write protecting form fields.

Feedback on 'Q799 Is it possible to have read only text in a text field?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.