How to make Nicedit only affect one textarea on a page as oposed to every textarea on the page

user1373823 picture user1373823 · Jun 12, 2012 · Viewed 13k times · Source

I've been trying to use nicedit (http://nicedit.com/) on a form for my website (which I am using to submit short stories). The form includes several textareas (). One of them is for the content of the short story, which i want to use nicedit on. The other text area is for tags, which i do not want to use nicedit on. However, nicedit gets applied to both.

This is the javascript code i am using to call up the nicedit code

<script type="text/javascript" src="core/rte.js"></script> <script type="text/javascript">
//<![CDATA[
bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
//]]>

I checked in the nicEdit.js and the allTextAreas() corresponds to this:

allTextAreas : function(nicOptions) {
var textareas = document.getElementsByTagName("textarea");
for(var i=0;i<textareas.length;i++) {
nicEditors.editors.push(new nicEditor(nicOptions).panelInstance(textareas[i]));
}
return nicEditors.editors;
},

I also investigated on the ingetnet and could find no answer as to how to make only one text area be affected by the nicedit code. Can anyone help?

Answer

Nathan Wall picture Nathan Wall · Jun 12, 2012

From looking at the code you posted, this should work:

<script type="text/javascript" src="core/rte.js"></script>
<script type="text/javascript">
//<![CDATA[
bkLib.onDomLoaded(function() {
    nicEditors.editors.push(
        new nicEditor().panelInstance(
            document.getElementById('myNicEditor')
        )
    );
});
//]]>
</script>

Just give your textarea whichever id you use:

<textarea id="myNicEditor"></textarea>