
Javascript can't get textarea value of ckeditor
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.
-
Related Reading
- Javascript multidimensional array (create, add and r
- Remove text after clicking in the textbox and then d
- Javascript get referrer url(previous page url), curr
- Javascript get current url, domain from url, relativ
- Javascript convert hex to decimal, binary to hex, oc
- Javascript delay loading images to improve web page
- Remove html element javascript by their parent or cl
- Javascript get all input elements in form and all im
- Javascript sets the element height that cannot be au
- Javascript create element(div,li,img,span) dynamical
- Javascript click child element to add onclick to par
- Mod operator and rounding off numbers in javascript