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