PDA

View Full Version : Setting Element to Readonly



johnnyi
01-20-2006, 06:19 PM
Howdy all,

If I have a textbox, such as:

<textarea name="mytext" id="mytext" rows="2" columns="50">

I know I can add a readonly attribute to it to lock it down, such as:

<textarea READONLY name="mytext" id="mytext" rows="2" columns="50">

Question is this: via JavaScript, can I set this textarea as READONLY?

What I'm trying to accomplish here is that after a user enters their text into the <textarea>, when they click a certain button, I'd like to lock down the textarea as READONLY via a JavaSript thereby locking their comments.

This obviously doesn't work:


function lockit()
{
document.getElementByID('mytext') = READONLY;
}


I know I'm missing something here (see red):


function lockit()
{
document.getElementByID('mytext')._____ = READONLY;
}


...but can't figure out what and haven't been able to successfully Google search either...

Any help would be greatly appreciated...

Thanks,

- I

johnnyi
01-20-2006, 06:22 PM
:rolleyes:
BOINK...

scratch that... this will do:



function lockit()
{
document.getElementByID('mytext').disabled = true;
}


Sorry for the brain fart.

- I

Twey
01-20-2006, 06:28 PM
.readonly = true should work too, and better (no greying-out of the element).