Setting a textarea to read only

L

Lovens Weche

I'm trying to set the "readonly" attribute of a "textarea" element this way:

---------------------------------

<script type="text/javascript">

***snip***



//-- create text area element --

var objTextArea;

objTextArea = document.createElement('textarea');

objTextArea.setAttribute('id', 'textArea' + this.InfoBoxID);

objTextArea.setAttribute('rows', this.TextAreaRows);

objTextArea.setAttribute('cols', this.TextAreaCols);

objTextArea.setAttribute('readonly', 'readonly');

document.getElementById('masterDiv').parentNode.appendChild(objTextArea);

document.getElementById('textArea' + this.InfoBoxID).style.position =
'absolute';

document.getElementById('textArea' + this.InfoBoxID).innerHTML =
textInTextArea;

//------------------------------



***snip***

</script>

</head>

<body onload="Onload();" bgcolor="#FFFF99">

<div id="masterDiv"></div>

</body>

---------------------------------

In this code, the textarea is never set to read only. I can always change
the content.

Also how can I had a node without the need to create the <div> masterDiv??

Thanks in advance!


=============================
Lovens Weche
Sirinik Team - "Games you can't live without"
www.sirinikteam.com
=============================
 
M

Martin Honnen

Lovens said:
I'm trying to set the "readonly" attribute of a "textarea" element this way:
objTextArea = document.createElement('textarea');
objTextArea.setAttribute('readonly', 'readonly');

Use the HTML DOM as follows
objTextArea.readOnly = true;
that has much better cross browser support than setAttribute has in HTML
documents.
 
L

Lovens Weche

ok it works now... Thanks Martin!

Lovens

Martin Honnen said:
Use the HTML DOM as follows
objTextArea.readOnly = true;
that has much better cross browser support than setAttribute has in HTML
documents.
 

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

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top