problem to disable or enable READONLY attribute

M

Matt

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">
<HTML>
<HEAD>
<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);
}
else
{ disableControls(true);
}
}
</script>
</head>
<body>
<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"
onClick="cbIgnoreValidation_onclick()">&nbsp;Ignore
Validation&nbsp;
</form>
</body>
</html>
 
R

rf

I encountered the problem to disable or enable READONLY attribute.
function disableControls(bValue)
{
InputForm.h1.disabled = bValue;
InputForm.h2.readonly = bValue;>

InputForm.h2.readOnly = bValue;

Note the O.
<P>Field With READONLY ATTRIBUTE: <INPUT TYPE="TEXT" name="h2" size=25
maxlength=6 value="readonly field" READONLY>

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top