user3722851
user3722851

Reputation: 147

Javascript can not set value inside of Textarea

I refer below example,

http://jsfiddle.net/rHDh9/

In example , if you click anywhere inside of textarea and if you click to button , it gets button value and sets to textarea where mouse clicked.

My question:

If i use below textarea , when i click to button , input value sets to textarea where mouse clicked.

<div id="100000000">

<input id="insertPattern" type="button" value="insert pattern" />
<textarea class="ckeditor" id="aboutme">insert some text into this string</textarea>

 </div>

However if i use below Html.TextArea , if i click to button , input value never sets to Html.Textarea where mouse clicked.

<div id="100000000">

    <input id="insertPattern" type="button" value="insert pattern" />
    @Html.TextArea("editor", new { @class = "ckeditor", @id = "aboutme" })

</div>

Why it works for textarea and not work for Html.TextArea on button click ?

Where i miss exactly ?

any help will be appreciated.

Thanks.

Upvotes: 0

Views: 2269

Answers (3)

Cyril Jacquart
Cyril Jacquart

Reputation: 2762

I had this problem when editor was inside a container displayed with animation (modal, animation...)

So, i solved the problem like this :

var _objEditor = null;
function show_editor_control(){
    $("#main_container").show('slide', {direction: 'left'}, 300);
    setTimeout(initialize_editor,300);
}

function initialize_editor(){
    if(_objEditor!=null) {_objEditor.destroy();};
    CKEDITOR.replace('textarea_id');
    _objEditor =CKEDITOR.instances["textarea_id"];
}

and for now, it works...

Upvotes: 0

Ondipuli
Ondipuli

Reputation: 468

If you are using CKEDITOR, you have to set values for text area like this.

CKEDITOR.instances['#aboutme'].setData('insert some text into this string');

Upvotes: 1

napo
napo

Reputation: 869

You shouldn't be using @id when constructing your TextArea (or any form element, for that matter). Just use id = "aboutme".

Upvotes: 1

Related Questions