You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

Support is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#117196 Update a JCE editor instance via JavaScript using its textarea ID

Posted in ‘Editor’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by Ryan on Friday, 02 May 2025 14:48 BST

webemus

Hi,

As part of my component, I'm providing users with the ability to translate text on the fly using a button placed next to form fields in the Joomla admin area. This feature works correctly with standard text and textarea fields.

However, it doesn't seem to work with fields using the JCE Editor. I need to programmatically update the content of a JCE editor instance, based on the id of the underlying <textarea> element.

Could you please advise how to properly target and update a JCE editor instance via JavaScript using its textarea ID?

Thanks in advance!

Ryan

This should be done using the Joomla Editor API, so assuming Joomla 5+, you would use:

const editor =  JoomlaEditor.get(id);
if (editor) {
    editor.setValue(value);
}

or

const editor = Joomla.editors.instances[id];
if (editor) {
    editor.setValue(value);
}

To set the value in a Tinymce compatible editor, like JCE or the Joomla core editor, you can also use:

const editor = tinymce.get(id);
if (editor) {
    editor.setContent(value);
}

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

webemus

Thans it worked for me, and  also to get th code I used:

const source_editor = Joomla.editors.instances[source_input_id];
			var string = source_editor.getValue();
const editor = Joomla.editors.instances[id];
if (editor) {
    editor.setValue(value);
}

Ryan

You also have access to:

const editor = Joomla.editors.instances[id];
if (editor) {
    // get selected text
    editor.getSelection();
    // overwrite selection
    editor.setSelection(value);
}

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.