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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:51:19+00:00 2026-06-05T03:51:19+00:00

Context I’m trying to build an answer to this WordPress question . I’m generating

  • 0

Context

I’m trying to build an answer to this WordPress question.

I’m generating dynamic checkboxes in the media upload thickbox window. And they should serve to populate a text field where the user can copy/paste its value.

The final output of the text field is the include attribute in this shortcode


.

Mainly, I need a helping hand to build this last part: Checkbox -> Populate/Unpopulate Text Field…


Layout

  1. Dynamic checkboxes

  2. Point of insertion of the text field (after the last <tr> shown in the console)

  3. Text field to be populated, should be include=" + CheckBoxID1 comma CheckBoxID2 comma etc + "

    enter image description here


Actual Code

<?php
add_action( 'admin_head-media-upload-popup', 'wpse_53803_script_enqueuer' );

function wpse_53803_script_enqueuer() {
    if( $_GET['tab'] == 'gallery' ) 
    {
        ?>
            <style>#media-upload th.order-head {width: 5%} #media-upload th.actions-head {width: 10%}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
    
                /* Iterate through the media items */
                $('.filename.new').each(function(i,e){
                    var id = $(this).next('.slidetoggle').find('thead').attr('id').replace(/media-head-/, '');
                    var filename = $('<label>Add to gallery list <input type="checkbox" name="gal-item-'+id+'" id="gal-item-'+id+'" value=""  /></label>').insertBefore($(this));
                    filename.css('float','right').css('margin-right','40px');

                    filename.id = id; // PROBLEM: not sure how to do this in Javascript
                    
                    // BUG: the alert is being fired twice
                    filename.click(function() {
                        alert('Handler for img id = '+filename.id+' called.');
                    });
                });                 
            });
            </script><?php
    }
}

Missing Parts

  • Create a dynamic text field to be populated.
  • Solve the problem and the bug noticed in the comments.
  • Make the filename.click(function() build the desired string inside the text field.
  • 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-06-05T03:51:21+00:00Added an answer on June 5, 2026 at 3:51 am

    You can do this using something similar to this

     $(document).on('change','input[type="checkbox"][name^="gal-item"]',function(){
        var checkedIds = $('input[type="checkbox"][name^="gal-item"]:checked')
                           .map(function(){
           return parseInt($(this).prop('name').replace(/gal-item-/,''));
        }).get();
    
        $('#shortcode').val('include="'+checkedIds.join(',')+'"');
    
    });
    

    You can replace document with any closer static container which you have to find by inspecting the add media markup. ​
    And You have find a element where you want to add the input field, add it like

    $('<span>





    </span>') .appendTo(TARGETIDORCLASS);

    Working DEMO

    And based on this your rewritten code would be something like

    jQuery(document).ready( function($) {
         //add input field
         $('<span>





    </span>') .appendTo(TARGETIDORCLASS); //bind checkbox change handler $(document).on('change','input[type="checkbox"][name^="gal-item"]',function(){ var checkedIds = $('input[type="checkbox"][name^="gal-item"]:checked').map(function(){ return parseInt($(this).prop('name').replace(/gal-item-/,'')); }).get(); $('#shortcode').val('include="'+checkedIds.join(',')+'"'); }); /* Iterate through the media items */ $('.filename.new').each(function(i,e){ var id = $(this).next('.slidetoggle') .find('thead') .attr('id') .replace(/media-head-/, ''); var filename = $('<label>Add to gallery list <input type="checkbox" name="gal-item-'+id+'" id="gal-item-'+id+'" value="" /></label>') .insertBefore($(this)); filename.css('float','right').css('margin-right','40px'); }); });

    This should work. I am in a hurry, couldn’t test much, check and let me know if you find any error, I would love to fix those.

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

Sidebar

Related Questions

Context is important for this question . So context first. I learned Symfony 3
Context This is a question mainly about Lucene (or possibly Solr) internals. The main
Context: We are building a framework for rapid delivery of WPF applications. This framework
Context: I setup a photo upload that uses an iframe to upload the image,
context: im writing a favicon parser: http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/includes/class-http.php and http://wp.leau.co/2011/03/18/handling-redirects-for-wp-favicons-with-redirects-set-to-0-with-wordpress-wp_remote_get/ I saw : http://www.foxfilm.nl/favicon.ico in
Context: So, I am attempting to build a ridiculously complex domain model. Talking with
Context: I was going to build app using mod_rewrite (front page loading child pages),
Context We have this application, using about 60 coding projects. We have several products
Context I'm learning C, and I'm trying to reverse a string in place using
Context I am trying to understand the internals of a big, hairy JavaScript library.

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.