473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting a textarea to read only

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.create Element('textar ea');

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

objTextArea.set Attribute('rows ', this.TextAreaRo ws);

objTextArea.set Attribute('cols ', this.TextAreaCo ls);

objTextArea.set Attribute('read only', 'readonly');

document.getEle mentById('maste rDiv').parentNo de.appendChild( objTextArea);

document.getEle mentById('textA rea' + this.InfoBoxID) .style.position =
'absolute';

document.getEle mentById('textA rea' + this.InfoBoxID) .innerHTML =
textInTextArea;

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

***snip***

</script>

</head>

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

<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 <divmasterDiv ??

Thanks in advance!
=============== ==============
Lovens Weche
Sirinik Team - "Games you can't live without"
www.sirinikteam.com
=============== ==============
Jul 30 '06 #1
2 16875


Lovens Weche wrote:
I'm trying to set the "readonly" attribute of a "textarea" element this way:
objTextArea = document.create Element('textar ea');
objTextArea.set Attribute('read only', 'readonly');
Use the HTML DOM as follows
objTextArea.rea dOnly = true;
that has much better cross browser support than setAttribute has in HTML
documents.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 30 '06 #2
ok it works now... Thanks Martin!

Lovens

"Martin Honnen" <ma*******@yaho o.dea écrit dans le message de news:
44************* **********@news read4.arcor-online.net...
>

Lovens Weche wrote:
>I'm trying to set the "readonly" attribute of a "textarea" element this
way:
>objTextArea = document.create Element('textar ea');
>objTextArea.se tAttribute('rea donly', 'readonly');

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

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3171
by: Matt | last post by:
I have a textarea that is populated from a blob within a database. Everytime the data is pulled, however, there is always a lot of leading space characters before the actual text. It is not in the database this way, so how might I specify more formatting parameters within the textarea? Matt Williams
4
5277
by: Simon | last post by:
I have another question.. Let's take a textarea with the parameter: "rows=4" (<textarea rows=4 onkeydown="CheckScrollbar()"> ) If you start typing the scrollbar at the right is not active. Only when you exceed the four lines (rows=4) the scrollbar becomes active. That moment..the moment the scrollbar becomes active..can javascript recognize/capture this moment? Thanks, Simon
4
23732
by: Chris Sharman | last post by:
I haven't specified fonts, leaving the user to have their chosen font. However, different tags render in different default fonts: text, input, & textarea all different from one another. I guess this is normal behaviour, but it looks poor, and I don't want our website to look that way (to out of the box browsers). How would I set textarea's 'like' input, or how would I determine (Javascript?) what's being used by an input field, to set...
12
1966
by: daniel kaplan | last post by:
Hi All, Been learning Javascript (via google) to create forms with pre-set values. As seen below. My problem I have found is this: I can't seem to figure out (or find so far via google) how to preset form options when the input type is a radio button, or dropdown list. The same method does not seem to work with input fields. Anyone know of such a comprehensive site?
21
3993
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does nothing in IE. I'd be greatful for any assistance. Also, if I will have problems the code on Opera or Safari, I'd appreciate any pointers--I don't have a Mac to test Safari. THanks very much, Michael
7
3766
by: daniel kaplan | last post by:
hello all, am new to HTML and am in the process of creating a form, no serious headaches, but am stumped on two types of fields. i can take care of these situations using javascript, but was adviced to only use javascript only when absolutely necessary, so am trying to find to see if i can handle these situations in HTML only. TEXTAREA field
3
2640
by: xscully | last post by:
Is there a way to force the user to read a textarea? Just like those 'agreements' that is used in a few offline instalation.. You have to scroll all the way down of the textarea and then the I AGREE button is enabled... is there a way to do that with JS? Tks a lot =]
3
1953
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g. <textarea name="NameOfTextArea" rows="5" cols="60">some text area</textarea>), as I want to then dynamically read back the controls' values Setting the ID attributes doesn't work, nor does the following:...
3
8188
by: zjw2112 | last post by:
Hello. I have some javascript code that dynamically creates a textarea and sets the wrap value to hard, which I thought would preserve CR/LF in the textarea: var otherTextArea = document.createElement("textarea"); otherTextArea.setAttribute("rows", "10"); otherTextArea.setAttribute("cols", "30"); otherTextArea.setAttribute("id", "otherTextArea"); otherTextArea.setAttribute("wrap", "hard");
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10190
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.