Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:19:19+00:00 2026-05-26T08:19:19+00:00

Possible Duplicate: Use javascript variable in object name I am using CKeditor as a

  • 0

Possible Duplicate:
Use javascript variable in object name

I am using CKeditor as a rich text editor. I have dynamically generated textareas with a unique ID that need replacing with text editors. That is working fine, but I then need to call getData(); on the textarea to get the data for an AJAX call. This is easy enough:

var editor_data = CKEDITOR.instances.editor1.getData();

The problem is I need editor1 to be dynamic, depending on the value of an attribute on a button. I record the textarea’s identifier in a sibling button’s name attribute:

var INSTANCE_NAME = $(this).attr('name');

Logging that out I get the correct editor ID back. (Note only using CAPS to highlight where it needs to be used in the next code block.)

I now need to use that INSTANCE_NAME as a variable like so:

var editor_data = CKEDITOR.instances.INSTANCE_NAME.getData();

I imagine my entire code needs to look something like this:

var INSTANCE_NAME = $(this).attr('name');
var editor_data = CKEDITOR.instances.INSTANCE_NAME.getData();

But I just get an error that CKEDITOR.instances.INSTANCE_NAME is undefined (which isn’t surprising really)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:19:19+00:00Added an answer on May 26, 2026 at 8:19 am

    There are two ways to access properties in an object:

    1. object.property
    2. object['property']

    Because the second option takes the property name as a string, you can build it dynamically — in this case, using the string INSTANCE_NAME:

    var INSTANCE_NAME = $(this).attr('name');
    var editor_data = CKEDITOR.instances[INSTANCE_NAME].getData();
    //                                  \_____________/
    //                                         ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Escape string for use in Javascript regex I have a msg like
Possible Duplicate: How do I enumerate the properties of a javascript object? I have
Possible Duplicate: Deleting Objects in JavaScript I have a JS object having a large
Possible Duplicate: Using a javascript variable to set PHP variable I need to do
Possible Duplicate: Javascript Objects: Dynamic variable names? I have a json string passed in
Possible Duplicate: Use JavaScript to place cursor at end of text in text input
Possible Duplicate: How to use javascript variables in jquery selectors This works $('input[name=nickname]').css(...); Now
Possible Duplicate: Difference between using var and not using var in JavaScript Hello, I
Possible Duplicate: When to Use Double or Single Quotes in JavaScript Are single quotes
Possible Duplicate: When to Use Double or Single Quotes in JavaScript I'm confusing what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.