By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,709 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,709 IT Pros & Developers. It's quick & easy.

Realtime change textarea wrap

P: n/a
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
Oct 24 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> "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="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


<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/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

P: n/a
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="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

<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/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

P: n/a
> "Fluffy Convict" <fl***********@hotmail.com> wrote:
news:11**************@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/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 discussion thread is closed

Replies have been disabled for this discussion.