Reputation: 5309
How to get the value of text area(tinymce)
using jQuery in Moodle
My text area code is:
$editor = \editors_get_preferred_editor();
$editor->use_editor("ans");
echo \html_writer::tag('textarea', '',
array('id' => "ans", 'name' => "ans", 'rows' => 5, 'cols' => 5));
My jQuery code to get the value of editor
field is:
var answer = $("#ans").val();
But this code is not working, gives nothing.
Upvotes: 0
Views: 642
Reputation: 539
Use tinymce api:
// Get the HTML contents of the currently active editor
console.debug(tinyMCE.activeEditor.getContent());
// Get the raw contents of the currently active editor
tinyMCE.activeEditor.getContent({format : 'raw'});
// Get content of a specific editor:
tinyMCE.get('content id').getContent();
Before this code check which editor user use (check if tinyMCE is null, try-catch etc.)
Upvotes: 2