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

  • Home
  • SEARCH
  • 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 3427166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:48:13+00:00 2026-05-18T06:48:13+00:00

I need to return som values I have selected in a jQuery UI Dialog

  • 0

I need to return som values I have selected in a jQuery UI Dialog box.

Currently I’m just setting the value like this:

jQuery('#fileBrowser input.addImage').live("click", function() {
  // 'file' is set when selected in file browser
  imageUrlInputBox.val(file);      // Add relative image url to text field
  jQuery("#fileBrowser").dialog("close");
});

The problem I face now however, is that I open the dialog box throug a custom button in TinyMCE. So I needed another way of inserting the image. This is what I came up with:

// This is the function valled when clicking the tinyMCE button
function openImageManager(ed) {        
  //tinymce is a global variable.      
  tinymce = ed; 
  jQuery("#fileBrowser").dialog("open");
}

The function receives the ‘ed’ variable passed from the tinyMCE plugin. Here is the script for that:

(function() {

    tinymce.create('tinymce.plugins.wp_filebrowser_plugin', {

        init : function(ed, url){
            ed.addButton('wp_filebrowser_plugin', {
                title : 'Insert image',
                onclick : function() {
                  openImageManager(ed) 
                },
                image: url + "/img/wand.png"
            });
        },

        getInfo : function() {
            return {
                longname : 'WP Filebrowser TinyMCE plugin',
            };
        }
    });

    tinymce.PluginManager.add('wp_filebrowser_plugin', tinymce.plugins.wp_filebrowser_plugin);
})();

Now, when clicking the insert button, I can execute the following code to insert data into the text editor:

jQuery('#fileBrowser input.addImage').live("click", function() {
  var img_html = '<img class="' + css_class + '" src="' + file_url + '" title="' + alt + '" alt="" />';
  tinymce.execCommand('mceInsertContent', false, img_html);  
});

SOLUTION
Thank’s to T.J. Crowder, I found the answer. The code is updated to reflect 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-18T06:48:13+00:00Added an answer on May 18, 2026 at 6:48 am

    You can’t do this:

    function openImageManager() {
      img_html = jQuery("#fileBrowser").dialog("open"); // I need some sort of callback here
      return img_html;
    }
    

    …because the interaction of your dialog with the user needs to be asynchronous to the openImageManager call, there’s no way to put the openImageManager function “on hold” while waiting for UI events (like the user doing something) to occur.

    What you need to do is show the dialog, and then elsewhere handle closing it and pasting the image into TinyMCE (e.g., sending an mceImage command via execCommand). You can’t have it as the return value of your openImageManager function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.