problem to disable or enable READONLY attribute

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I encountered the problem to disable or enable READONLY attribute.
This is my html file. When the user check the checkbox, it will enable
the field, and when the user uncheck the checkbox, it will make the
field read only.

If I use disable attribute, it is working fine. But I want to use
READONLY attribute. Field name h1 with disabled attribute is working
fine, but field name h2 is not working.  Any ideas?? Thanks!!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<TITLE>Exact Match Form</TITLE>
<script type="text/javascript">
//only affect standard fields
function disableControls(bValue)
    InputForm.h1.disabled = bValue;
    InputForm.h2.readonly = bValue;

function cbIgnoreValidation_onclick()
    if (InputForm.cbIgnoreValidation.checked == true)
    {    disableControls(false);
    {    disableControls(true);
<form name="InputForm">
<P>Field With DISABLED ATTRIBUTE: <INPUT TYPE="TEXT" name="h1" size=25
maxlength=6 value="disabled field" DISABLED>
<P>Field With READONLY ATTRIBUTE: <INPUT TYPE="TEXT" name="h2" size=25
maxlength=6 value="readonly field" READONLY>
<INPUT type="checkbox" name="cbIgnoreValidation"

Re: problem to disable or enable READONLY attribute

Quoted text here. Click to load it

InputForm.h2.readOnly = bValue;

Note the O.

Quoted text here. Click to load it

This could also be confusing you. You have specified a maximum length of 6
but have initialised the field with text that is more than 6 characters
long. Even if the field is not readonly you will not be able to type
characters in.


Site Timeline