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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:47:44+00:00 2026-06-12T22:47:44+00:00

I am trying to be super-concise, and have the following javascript code that listens

  • 0

I am trying to be super-concise, and have the following javascript code that listens for custom triggered events:

var concat = "";
$("body")
    .unbind("__evt_selgrps_ok")
    .bind("__evt_selgrps_ok", function(event, param) {
        $(param).each( function() {
            concat += $(this).attr("data-field-id");
        });
    });

The event is triggered using code as follows:

$("body")
    .trigger('__evt_selgrps_ok', 
    [$("#<%=DialogID%>").find(":input:checked")]);

Simply, the above gets all the input fields of Checkbox type, that are currently checked, and passes the array of elements as a parameter to the bound handlers (as per the first code example in this question).

Functionaly, this code works well. I just think that there is a lot of code to do something relatively simple, and that is to pass the “data-field-id” attribute values of all checked checkboxes, as a parameter to the trigger.

Ideally, a simple json array of the values passed to the trigger handler would be much better. The trigger handler shouldn’t really have to know about the input element, because it just wants to receive the array of attribute values.

I suppose, the bottom-line of my question is, how do you ask JQuery to give you an array of all the specified attribute using a certain selector.

I am only interested in a very nice concise solution, which preferably doesn’t involve using the ‘each’ function.

Thanks!
SR

  • 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-12T22:47:45+00:00Added an answer on June 12, 2026 at 10:47 pm

    You can use map() to project an array of attributes from a set of elements:

    var fieldIds = $("#<%=DialogID%> :input:checked").map(function() {
        return $(this).attr("data-field-id");
    }).get();
    

    In your case, you could use it like this:

    $("body").trigger("__evt_selgrps_ok",
        $("#<%=DialogID%> :input:checked").map(function() {
            return $(this).attr("data-field-id");
        }).get());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to do something that I think is super simple. i have 3
I trying to create inheritance so I can have some super classes with general
I'm trying to invoke a method that takes a super class as a parameter
I'm trying to make a Hyperlink that contains text with super- and/or subscripts. I've
I am trying to create a Super Column Family that will replicate a structure
I'm current a WebForms developer that is trying to move to MVC. I'm super
I am trying to change my XSLT so that when a super tag in
I'm trying to use a custom class to override a method in its super
I am trying to pass Map<String, Map<String, List<TranslationImport>>> variable to super class's constructor that
I'm trying to attempt something that seems super simple, but right now I want

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.