Javascript can't get textarea value of ckeditor

Lionsure 2020-06-19 Original by the website

When using the online editor ckeditor, by getting the id of the textarea of multiple lines of text, and then getting its value, a very strange problem occurs, the textarea value can not be got the first time, but the second time it is got, resulting in restrictions on the word count of text in textarea always fails.

 

The code is as follows(asp.net refers to ckeditor):

<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>

<asp:TextBox ID="tbContent" runat="server" class="ckeditor" TextMode="multiLine" Text='<%# Bind("info") %>'></asp:TextBox>

 

After the browser parses it becomes:

<textarea name="tbContent" rows="2" cols="20" id="tbContent" class="ckeditor"></textarea>

 

Javascript to get the textarea value code:

function gettextareaValue(obj)
       {
              var ta = document.getElementById(obj);
              return ta.value;
       }

Call: gettextareaValue("tbContent");

In this way, the textarea value can't be got for the first time, but it can be got for the second time.

 

You need to use the value method of ckeditor to get the value of textarea. The code is as follows:

function gettextareaData()
       {
              var cke = CKEDITOR.instances.tbContent;
              return cke.getData();
       }

 

It can be called directly, but there is one thing to note, just write the two sentences of gettextareaData() method as one sentence, such as:

CKEDITOR.instances.tbContent.getData();

Sometimes the value of textarea cannot be got, but it can be got as two sentences. Therefore, if you encounter a situation where one sentence is worthless, write two sentences separately. In addition, there are corresponding methods for other operations of ckeditor. If you encounter problems, don't forget to use the methods provided by it.