{"id":1373,"date":"2022-08-30T15:15:59","date_gmt":"2022-08-30T15:15:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/15\/tinymce-textareas-value-error-cant-solve-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:59","modified_gmt":"2022-08-30T15:15:59","slug":"tinymce-textareas-value-error-cant-solve-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/tinymce-textareas-value-error-cant-solve-collection-of-common-programming-errors\/","title":{"rendered":"tinymce textareas value error &#8211; cant solve-Collection of common programming errors"},"content":{"rendered":"<pre><code>$('.button-save').click(function(b){\n                b.preventDefault();\n                var title = $('#title').val(),\n                    category = $('#category').val(),\n                    file = $('#file').val(),\n                    short_content = tinyMCE.get('#short_content').getContent(),\n                    content = tinyMCE.get('#content').getContent(),\n                    date = $('#date').val(),\n                    language = $('#language').val();\n                alert(short_content);\n                $.ajax({\n                    type: 'POST',\n                    url: '\/admin\/save',\n                    data: {\n                        title:title,\n                        category:category,\n                        file:file,\n                        short_content:short_content,\n                        content:content,\n                        date:date,\n                        language:language\n                    },\n                    success: function(data){\n                        $('.adm-notification').html(data);\n                    }\n                });\n            });\n<\/code><\/pre>\n<p>As you see there are two textareas (short_content,content); I tried to get them via tinyMCE.get(&#8216;#content&#8217;).getContent(). But i&#8217;m getting the error<\/p>\n<blockquote>\n<p>Uncaught TypeError: Cannot call method &#8216;getContent&#8217; of undefined<\/p>\n<\/blockquote>\n<p>HTML code<\/p>\n<pre><code> \n            \n                Page title (required)\n                \n            \n            \n                Category (required)\n                \n            \n            \n                Attachments\n                \n            \n            \n                Short content (required)\n                \".$edit['short_content'].\"\n            \n            \n                Long content (required)\n                \".$edit['content'].\"\n            \n            \n                Date (required)\n                \n            \n            \n                Language (required)\n                \n            \n            \n                Save page\n            \n        \n<\/code><\/pre>\n<p>How to fix?<\/p>\n<ol>\n<li>\n<p>You need to supply the <code>id<\/code> of the textarea, without the <code>#<\/code>.<\/p>\n<pre><code>tinyMCE.get('long_content').getContent()\ntinyMCE.get('short_content').getContent()\n<\/code><\/pre>\n<p>btw, you need to decide whether you want to submit the form or read out the value with JavaScript and then send it to the server. Here a solution reading it out with JS:<\/p>\n<pre><code>\n    tinyMCE.init({\n            mode : \"textareas\"\n    });\n\n\n    $(function(){\n        $('#button-save').click(function(){\n            console.log(\"ok\");\n            var short_content = tinyMCE.get('short_content').getContent();\n            var content = tinyMCE.get('long_content').getContent();\n            alert(short_content);\n            alert(content);\n        });\n    });\n\n\n\n'short_content'\n'content'\n\nSave page\n<\/code><\/pre>\n<p>Same as a working fiddle.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-15 09:06:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>$(&#8216;.button-save&#8217;).click(function(b){ b.preventDefault(); var title = $(&#8216;#title&#8217;).val(), category = $(&#8216;#category&#8217;).val(), file = $(&#8216;#file&#8217;).val(), short_content = tinyMCE.get(&#8216;#short_content&#8217;).getContent(), content = tinyMCE.get(&#8216;#content&#8217;).getContent(), date = $(&#8216;#date&#8217;).val(), language = $(&#8216;#language&#8217;).val(); alert(short_content); $.ajax({ type: &#8216;POST&#8217;, url: &#8216;\/admin\/save&#8217;, data: { title:title, category:category, file:file, short_content:short_content, content:content, date:date, language:language }, success: function(data){ $(&#8216;.adm-notification&#8217;).html(data); } }); }); As you see there are two textareas (short_content,content); I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1373","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1373"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1373\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}