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

Related Questions

I created a UITableViewCell in Xcode 4 using IB. But for some weird reason
Created using Sphinx 0.6.5. I know Python's documentation uses reStructuredText , but it has
Created a simple jquery-nivo-like slider using wpf and want to add an animation between
just created an UITableView, trying to display some custom data from an array, but
I created a python server on port 8000 using python -m SimpleHTTPServer . When
Created an Accordion side bar using jQuery 1.2.6. I cannot access newer version of
Created a button in my aspx file and add its click method in the
created a singleview application with storyboard. Added three viewcontrollers apart from the one view
Created basic C++ DLL and exported names using Module Definition file (MyDLL.def). After compilation
Created a profile using content provider. After running it correctly, added 3 fields to

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.