Nicedit not working in other textareas

Asked

Viewed 100 times

0

I am creating a kind of forum on my client’s site. In this forum, to ask questions and comments, obviously use Textareas.

However, I am using the Nicedit class to transform my textareas with option of font, size, insertion of images and links etc. Only the page has two textareas with ids "post" and comment". And it’s only working the textarea "post". I had to put the code like this:

<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function () {
    var textareas = document.getElementsByName("postar");

    for(var i=0;i<textareas.length;i++)
     {
        var myNicEditor = new nicEditor();
        myNicEditor.panelInstance(textareas[i]);

     }

    //var textareas2 = document.getElementsByName("comentar");

    //for(var i=0;i<textareas2.length;i++)
    // {
    //    var myNicEditor = new nicEditor();
    //    myNicEditor.panelInstance(textareas2[i]);

    // }
});
</script>

So my comment textareas are normal. What could I do to enable comments textareas normally with Nicedit?

1 answer

1

Add a class in textarea that you want to instantiate the editor:

<textarea class="meueditor" name="postar"></textarea>
<textarea class="meueditor" name="comentar"></textarea>

Then just simplify the code by searching for the name of class:

bkLib.onDomLoaded(function () {
    var textareas = document.getElementsByClassName("meueditor");
    var myNicEditor = new nicEditor();
    for(var i=0;i<textareas.length;i++)
    {
        myNicEditor.panelInstance(textareas[i]);
    }
});

No need to include var myNicEditor = new nicEditor(); inside the loop for. Just invoke it once.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.