Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to get the text written inside a TinyMCE textarea

I'm trying to get the text written inside a TinyMCE textarea. I have the code below. The TinyMCE text area is showed but the alert is not even showed. Why?

<html>
    <head></head>
    <body>
        <script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js'></script> 
        <script type="text/javascript" src="/home/javiergarcia/Scaricati/jari/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
        <script type="text/javascript"> 
            tinyMCE.init({
                mode : "textareas",
            });

            $(document).ready(function() {
                $('form').submit(function() {
                    //alert("fasdfs");
                    alert(tinyMCE.get('#jander').getContent());
                });
            });
        </script>
        <form method="post" action="somepage">
            <textarea name="content" id="jander" style="width:100%"></textarea> 
            <input type="submit">
        </form>
    </body>
</html>

Regards

Javier

like image 427
ziiweb Avatar asked Mar 25 '11 09:03

ziiweb


People also ask

How do I get content from TinyMCE textarea?

The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.

How do I get the content of TinyMCE editor in jQuery?

You can use the activeEditor for that, or if (for some reason) you have the original element that created the editor in a jQuery object, you can use that jQuery object to get the id of the original element and use that in order to get the content of the TinyMCE (using the TinyMCE editor).


4 Answers

Why don't you simply use tinymce.get('jander').getContent(); (tinymce in lowercases!) ?

like image 73
Thariama Avatar answered Oct 21 '22 21:10

Thariama


You should simply request the value of the original textarea control.

tinyMCE.triggerSave(false, true);
$('#jander').val();
like image 36
Brian Scott Avatar answered Oct 21 '22 20:10

Brian Scott


Once you've included the TinyMCE jQuery plugin, you assign the editor to a variable and can then operate any jQuery function on it:

var wysiwyg = $('textarea.tinymce').tinymce(tinymce_settings);

Then to get the contents you can just fetch wysiwyg.html();

Also, see the TinyMCE jQuery documentation for other manipulation techniques.

like image 38
Dunhamzzz Avatar answered Oct 21 '22 21:10

Dunhamzzz


As someone told me, the sharp character (#) is used in jQuery selectors and has nothing to do with tinyMCE.get(). So with this line below works ok.

alert(tinyMCE.get('jander').getContent());   
like image 44
ziiweb Avatar answered Oct 21 '22 19:10

ziiweb