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 935759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:12:27+00:00 2026-05-15T21:12:27+00:00

I created a SplitButton in TinyMCE and I am using a for loop to

  • 0

I created a SplitButton in TinyMCE and I am using a for loop to add buttons, but for some reason the buttons’ onclick is always calling the same one (the last from the for loop). It seems every time I add a menu option, the callback is being overwritten.

Let me describe what I mean.

var c = cm.createSplitButton('optionsList', {
title : 'Options',
});

c.onRenderMenu.add(function(c, m){
var Opts1 = options[0];
var Opts2 = options[1];
var Opts3 = options[2];

var sub1 = m.addMenu({title: "Options 1"});
for(var x in Opts1){
    sub1.add({title: Opts1[x], onclick: function(){
        tinyMCE.activeEditor.execCommand('mceInsertContent',false,Opts1[x]);
    }});
}

var sub2 = m.addMenu({title: "Options 2"});
for(var y in Opts2){
    sub2.add({title: Opts2[y], onclick: function(){
        tinyMCE.activeEditor.execCommand('mceInsertContent',false,Opts2[y]);
    }});
}

var sub3 = m.addMenu({title: "Options 3"});
for(var z in Opts3){
    sub3.add({title: Opts3[z], onclick: function(){
        tinyMCE.activeEditor.execCommand('mceInsertContent',false,Opts3[z]);
    }});
}

});

The menus are created correctly, but for example if I select ‘Options 1’ and select any option, tinyMCE will print the last option from that subMenu. I don’t know how to fix this.

  • 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-15T21:12:28+00:00Added an answer on May 15, 2026 at 9:12 pm

    I fixed it, so I’ll answer my own question. I needed to use a closure. The solution was:

    var insertVar = function(val){
        return function(){tinyMCE.activeEditor.execCommand('mceInsertContent',false,val);}
    };
    
    var sub1 = m.addMenu({title: "Options 1"});
    for(var x in Opts1){
        var variable = insertVar(Opts1[x]);
        sub1.add({title: Opts1[x], onclick: variable});
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this line ffmpeg -i video.flv -an -vcodec png -vframes… May 16, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer I've logged a bug here: Pl go thru it and… May 16, 2026 at 3:47 pm
  • Editorial Team
    Editorial Team added an answer It might be that, when reading from a stream-based socket,… May 16, 2026 at 3:47 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

i created a datalayer using subsonic. however when i am selecting my data, i
I created one apps and successfully submitted into AppStore. Now my client wants to
I'm trying to create a SplitButton control that uses a ContextMenu to display its
I've a custom SplitButton implementation in which contains a ComboBox with several ComboBoxItems bound
Microsoft's User Experience Interaction Guidelines give some UI guidelines for when to use a
Created .NET WCF service, tested it - works. Generated schemas from Data and service
Created a stored procedure in SQL 9 (2005) and have since upgraded to SQL
Created a Java application to upload documents via CIS (Content Integration Suite) to a
Created by Microsoft as the foundation of its .NET technology, the Common Language Infrastructure
created an Eclipse plugin that contributes to the UI by a new project wizard

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.