Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Form | 3.6 | Q799 [ previous next ]

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?'

©2018 Martin Webb