473,729 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Realtime change textarea wrap

I am trying to write a script that changes a textarea wrap realtime,
basically like you can switch to and from "wordwrap" in Microsofts
Notepad. Because of a bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does not
listen to the textarea.wrap = 'soft' command. Because I want the script
to be cross-browser compatible, someone suggested to remove and
immediately add a node to the DOM, so I now have:

----------------------------------------------------------------------
<img src="images/wordwrap.gif" onclick="wordWr ap();"><br>
<textarea id="editor" wrap="off">Cont ent</textarea>

function wordWrap() {
var txtarea = document.getEle mentById('edito r');
wrap = txtarea.getAttr ibute('wrap');

if (wrap.toLowerCa se() == 'off') { /* this is line 8 */
txtarea.setAttr ibute('wrap', 'soft');
txtarea.setAttr ibute('id', 'editor');
var parNod = txtarea.parentN ode, nxtSib = txtarea.nextSib ling;
parNod.removeCh ild(txtarea); parNod.insertBe fore(txtarea, nxtSib);
}
else {
txtarea.setAttr ibute('wrap', 'off');
txtarea.setAttr ibute('id', 'editor');
var parNod = txtarea.parentN ode, nxtSib = txtarea.nextSib ling;
parNod.removeCh ild(txtarea); parNod.insertBe fore(txtarea, nxtSib);
}
}
----------------------------------------------------------------------

By default, the textarea wrap is set to "off". If I then click
wordwrap.gif, the wrap is actually set "soft". But if I click again, the
wrap doesn't change back into "off". FireFox generates the following error:

Error: wrap has no properties
Source File: http://192.168.0.2/cms/system/js/editor.js
Line: 8

Secondly, IE doesn't respond to this script at all.

-> What am I missing here? As far as I know, this script should work. It
might be a bit dirty, but that's because I have to work around the
FireFox bug. Any help would be greatly appreciated!

Cheers, Dennis
Oct 24 '05 #1
3 6772
> "Fluffy Convict" <fl***********@ hotmail.com> wrote:
news:11******** *******@news.is ion.nl....

I am trying to write a script that changes a textarea wrap realtime,
basically like you can switch to and from "wordwrap" in Microsofts
Notepad. Because of a bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does
not listen to the textarea.wrap = 'soft' command. Because I want the
script
to be cross-browser compatible, someone suggested to remove and
immediately add a node to the DOM, so I now have:

----------------------------------------------------------------------
<img src="images/wordwrap.gif" onclick="wordWr ap();"><br>
<textarea id="editor" wrap="off">Cont ent</textarea>

function wordWrap() {
var txtarea = document.getEle mentById('edito r');
wrap = txtarea.getAttr ibute('wrap');

if (wrap.toLowerCa se() == 'off') { /* this is line 8 */
txtarea.setAttr ibute('wrap', 'soft');
txtarea.setAttr ibute('id', 'editor');
var parNod = txtarea.parentN ode, nxtSib = txtarea.nextSib ling;
parNod.removeCh ild(txtarea); parNod.insertBe fore(txtarea,
nxtSib); }
else {
txtarea.setAttr ibute('wrap', 'off');
txtarea.setAttr ibute('id', 'editor');
var parNod = txtarea.parentN ode, nxtSib = txtarea.nextSib ling;
parNod.removeCh ild(txtarea); parNod.insertBe fore(txtarea,
nxtSib); }
}
----------------------------------------------------------------------

By default, the textarea wrap is set to "off". If I then click
wordwrap.gif, the wrap is actually set "soft". But if I click again,
the wrap doesn't change back into "off". FireFox generates the
following error:

Error: wrap has no properties
Source File: http://192.168.0.2/cms/system/js/editor.js
Line: 8

Secondly, IE doesn't respond to this script at all.

-> What am I missing here? As far as I know, this script should work.
It might be a bit dirty, but that's because I have to work around the
FireFox bug. Any help would be greatly appreciated!

Cheers, Dennis


<script type="text/javascript">
function wordWrap() {
var txtarea = document.getEle mentById('edito r');
wrap = txtarea.getAttr ibute('wrap');
(wrap.toLowerCa se() == 'off')?
txtarea.setAttr ibute('wrap', 'soft'):
txtarea.setAttr ibute('wrap', 'off');
/*Fix display for mozilla*/
txtarea.style.d isplay='none';
txtarea.style.d isplay='';
}
</script>

http://files.photojerk.com/files/fil...xtareaWrap.htm

--
BootNic Monday, October 24, 2005 4:46 PM

A sense of humor is the lubricant of life's machinery.
*Unknown*

Oct 24 '05 #2
BootNic wrote:
"Fluffy Convict" <fl***********@ hotmail.com> wrote:
news:11****** *********@news. ision.nl....

I am trying to write a script that changes a textarea wrap realtime,
basically like you can switch to and from "wordwrap" in Microsofts
Notepad. Because of a bug
(https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does
not listen to the textarea.wrap = 'soft' command. Because I want the
script
to be cross-browser compatible, someone suggested to remove and
immediately add a node to the DOM, so I now have:

----------------------------------------------------------------------
<img src="images/wordwrap.gif" onclick="wordWr ap();"><br>
<textarea id="editor" wrap="off">Cont ent</textarea>

function wordWrap() {
var txtarea = document.getEle mentById('edito r');
wrap = txtarea.getAttr ibute('wrap');

if (wrap.toLowerCa se() == 'off') { /* this is line 8 */
txtarea.setAttr ibute('wrap', 'soft');
txtarea.setAttr ibute('id', 'editor');
var parNod = txtarea.parentN ode, nxtSib = txtarea.nextSib ling;
parNod.removeCh ild(txtarea); parNod.insertBe fore(txtarea,
nxtSib); }
else {
txtarea.setAttr ibute('wrap', 'off');
txtarea.setAttr ibute('id', 'editor');
var parNod = txtarea.parentN ode, nxtSib = txtarea.nextSib ling;
parNod.removeCh ild(txtarea); parNod.insertBe fore(txtarea,
nxtSib); }
}
----------------------------------------------------------------------

By default, the textarea wrap is set to "off". If I then click
wordwrap.gi f, the wrap is actually set "soft". But if I click again,
the wrap doesn't change back into "off". FireFox generates the
following error:

Error: wrap has no properties
Source File: http://192.168.0.2/cms/system/js/editor.js
Line: 8

Secondly, IE doesn't respond to this script at all.

-> What am I missing here? As far as I know, this script should work.
It might be a bit dirty, but that's because I have to work around the
FireFox bug. Any help would be greatly appreciated!

Cheers, Dennis

<script type="text/javascript">
function wordWrap() {
var txtarea = document.getEle mentById('edito r');
wrap = txtarea.getAttr ibute('wrap');
(wrap.toLowerCa se() == 'off')?
txtarea.setAttr ibute('wrap', 'soft'):
txtarea.setAttr ibute('wrap', 'off');
/*Fix display for mozilla*/
txtarea.style.d isplay='none';
txtarea.style.d isplay='';
}
</script>

http://files.photojerk.com/files/fil...xtareaWrap.htm

BootNic, thanks for you quick reply. This works like a charm in IE, but
in FF, I get no response whatsoever?
Oct 24 '05 #3
> "Fluffy Convict" <fl***********@ hotmail.com> wrote:
news:11******** ******@news.isi on.nl....

BootNic wrote:
<snip>
BootNic, thanks for you quick reply. This works like a charm in IE,
but in FF, I get no response whatsoever?


It worked on my FF 0.8.0, Mozilla 1.7.12 and IE6.

The only thing I seen that may make it appear not to work would be if
there is not enough text in the text area to change the appearance,
which would make it appear to do nothing.

Did you get the same results with the sample link?

http://files.photojerk.com/files/fil...xtareaWrap.htm

In any case I have no other thoughts at the moment.
--
BootNic Monday, October 24, 2005 6:08 PM

Inform all the troops that communications have completely broken down.
*Ashleigh Brilliant*
Oct 24 '05 #4

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

Similar topics

3
32417
by: Sunil Kulkarni | last post by:
I need to validate my TextArea as follows: 1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS 2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW I need some kind of a JS validation for the same. I have tried using hard wrap but that doesnt help completely. Any help in this matter would be very much appreciated! Thanks!
5
11226
by: chin | last post by:
Hi, I am trying to retrieved the value of the textarea with the newline preserved without having to submit the form to the server. Does anyone knows how to? I tried soft and hard wrap but both does not seems to affect the input in anyway. Example : <form name=frm> <textarea name=ta wrap="soft"></textarea> </form>
4
4259
by: TJS | last post by:
can the rows and columns of a textarea element with an id be changed on the fly ? if so is there an example ?
8
53018
by: Mark D. Smith | last post by:
Hi I have googled but not found a solution to wordwrap in a textarea using firefox/netscape. is there a style sheet solution or am i stuck with not being able to force wrapping in a textarea Mark
2
19281
by: mattrapoport | last post by:
Hello, I am have a div and inside of that div I have a textarea. There is nothing else in the div. The text in the textarea will come from a database so it needs to be able to wrap and grow as necessary. I've tried a whole bunch of permutations and I'm not having any luck. Any help would be greatly appreciated. Here's the code: HTML: <div class='desc'><textarea class='desc_text'>blah blah blah blah blah blah blah blah blah blah...
3
8185
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");
20
2276
by: Tony B | last post by:
I'm learning a little about using forms in php to enter data, and have a couple of questions re textarea. At the moment I just use "addslashes() to process the value from textarea so that punctuation is escaped, and write this into a table. When the text wraps in the text box I get a new line in the value returned, as well as new lines that I enter manually. Is it possible to remove the wrap new line but keep the user entered new line ?
1
2441
by: RFleming | last post by:
I attempted to use the advice below, but still I keep getting word wrap in my inputtextarea. I am very new to XML and CSS, and I do not totally understand the layout. Below is the single XML line I am modifying: <h:inputTextarea binding="#{RaceReport.txtRiderInfo}" wordWrap="true" id="txtRiderInfo" style="border-width: 2px; border-style: solid; font- family: 'Courier New','Courier',monospace; font-size: 12px; height: 75%; left: 24px;...
0
8921
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
8763
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
9427
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
9202
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
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
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.