Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Realtime change textarea wrap

0 views
Skip to first unread message

Fluffy Convict

unread,
Oct 24, 2005, 3:38:30 PM10/24/05
to
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="wordWrap();"><br>
<textarea id="editor" wrap="off">Content</textarea>

function wordWrap() {
var txtarea = document.getElementById('editor');
wrap = txtarea.getAttribute('wrap');

if (wrap.toLowerCase() == 'off') { /* this is line 8 */
txtarea.setAttribute('wrap', 'soft');
txtarea.setAttribute('id', 'editor');
var parNod = txtarea.parentNode, nxtSib = txtarea.nextSibling;
parNod.removeChild(txtarea); parNod.insertBefore(txtarea, nxtSib);
}
else {
txtarea.setAttribute('wrap', 'off');
txtarea.setAttribute('id', 'editor');
var parNod = txtarea.parentNode, nxtSib = txtarea.nextSibling;
parNod.removeChild(txtarea); parNod.insertBefore(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

BootNic

unread,
Oct 24, 2005, 4:47:22 PM10/24/05
to
> "Fluffy Convict" <fluffy...@hotmail.com> wrote:
> news:11301827...@news.ision.nl....

<script type="text/javascript">


function wordWrap() {
var txtarea = document.getElementById('editor');
wrap = txtarea.getAttribute('wrap');

(wrap.toLowerCase() == 'off')?


txtarea.setAttribute('wrap', 'soft'):

txtarea.setAttribute('wrap', 'off');
/*Fix display for mozilla*/
txtarea.style.display='none';
txtarea.style.display='';
}
</script>

http://files.photojerk.com/files/files/1130186460/textareaWrap.htm

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

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

Fluffy Convict

unread,
Oct 24, 2005, 5:26:36 PM10/24/05
to
BootNic, thanks for you quick reply. This works like a charm in IE, but
in FF, I get no response whatsoever?

BootNic

unread,
Oct 24, 2005, 6:08:18 PM10/24/05
to
> "Fluffy Convict" <fluffy...@hotmail.com> wrote:
> news:11301891...@news.ision.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/files/1130186460/textareaWrap.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*


0 new messages