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