# Solved: conditional toggling of readonly attribute of <input> tag



## andynic (May 25, 2007)

Hi.

I have two related fields in a form, a tag and a corresponding tag.
The tag has options:
Show all on one page
Display by year
A specific number per page

The relatind :

Upon entry to the form, the select field is set to ALL and the input field has state readonly.
If the user selects "Display by year" the input field should remain readonly.
If the user selects "A specific number per page" the input field should become read/write.
If the user changes his/her mind and decides to use the ALL or PER_YR option, the input field should return to readonly.

I have tried code like this on the field:
onchange="if ( document.getElementById('nrOfNewsItems').value == 'N' )
{
document.getElementById('nrPerPg').readonly = 'readwrite';
}
else
{
document.getElementById('nrPerPg').readonly = 'readonly';
}"
The above onchange code does not work.

Is there a straightforward way to do what I am attempting?

Thanks for your help.
Andynic


----------



## allnodcoms (Jun 30, 2007)

Hi Andy,

The HTML DOM input object read only attribute is camel case - 'readOnly' - and accepts 'true' and 'false' parameters. That should solve your problem, but if it doesn't I'd try 'disabled', which does the same thing and again accepts true / false.

Good luck!

Danny


----------



## andynic (May 25, 2007)

Hi Danny,
Thanks, that got me on the right track. The upper case O in readOnly is critical.
I ended up with a construction something like the code below. Note that in the "tobble back" button, I set readOnly = '' (that's two single quotes). Using 'false' does not work, at least not in Firefox v16.
<?php
echo <<<A

A;
?>


----------

