TinyMCE - Toggle controls for different textareas

Posted on 2009-04-28
Last Modified: 2012-05-06
Hi folks,

The code below initialises TinyMCE and doesnt load it into any text area which is exactly what I want - When I click on the toggle button for a particular control it loads in the TinyMCE editor fine (only since i added the id=document.getElementById(id) part) but when I click the toggle button on another textarea it unloads the control from the previous textarea, and when i click the this button again it then loads into this new <textarea>

I have about 10 <textarea> on my form, and i basically want to load controls in and out of these when the user requires. Can anyone point me in the right direction?

Browser: IE 7



        mode : "none", 


        theme : "advanced"




function toggleEditor(id) 



    id = document.getElementById(id);


    if (!tinyMCE.get(id))

        tinyMCE.execCommand('mceAddControl', true, id);


        tinyMCE.execCommand('mceRemoveControl', true, id);



<textarea name="MyTextArea" style="width:100%">


<a href="javascript:toggleEditor('MyTextArea');">Enter text</a>

Open in new window

Question by:DevSure
    1 Comment
    LVL 15

    Accepted Solution

    You don't need getElementById, I guess the problem was in undefined ID attribute for your textarea. Check the following:

    function toggleEditor(id)
        if (!tinyMCE.get(id))
            tinyMCE.execCommand('mceAddControl', true, id);
            tinyMCE.execCommand('mceRemoveControl', true, id);

    <textarea name="MyTextArea" id="MyTextArea"  style="width:100%">

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now