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 7817251

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:10:19+00:00 2026-06-02T06:10:19+00:00

I have a tree with checkboxes and their id has key for item and

  • 0

I have a tree with checkboxes and their id has key for item and value as their value.

<input type="checkbox" name="list_code[4]" id="list_code[4]" value="AG12345678" checked="checked">

When users select a tree element I can access those by

$('input[name^="list_code"]').each(function() {
    if ($(this).attr('checked')) 
        list_code = $(this).val();
});

I am able to get value AG12345678 but I need to get key value too which is 4 from list_code[4] in this case. How can I access that value?

  • 0 0 Answers
  • 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-02T06:10:21+00:00Added an answer on June 2, 2026 at 6:10 am
    var n = this.id.slice(this.id.indexOf('[') + 1, this.id.indexOf(']'));
    

    or…

    var n = this.id.replace(/\D/g, '');
    

    or…

    var n = (this.id.match(/\d+/) || [])[0];
    

    or if there could be other unwanted numbers…

    var n = (this.id.match(/\[(\d+)\]/) || [])[1];
    

    Or if you control the source, a good solution would be to use a data- attribute for future HTML5 support…

    <input type="checkbox" data-number="4" name="list_code[4]" id="list_code[4]" value="AG12345678" checked="checked">
    

    …then in HTML5 browsers, you could do…

    this.data.number;
    

    …or for legacy support, you could do…

    this.getAttribute('data-number');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form <form> <input type=text name=Name /> <input type=checkbox name=Feature.Translate /> <input
Assuming I have a tree structure UL --LI ---INPUT (checkbox) And I want to
I have a tree build with ul and li. Each li has an checkbox
I have a tree structure where each Node has a parent and a Set<Node>
I have a tree view defined as follows: <HierarchicalDataTemplate x:Key=ChildTemplate ItemsSource={Binding Children}> <TextBlock Text={Binding
I have a tree view which has a folder icon by default and once
I have a checkbox node tree build based on a named vector . And
I have a custom checkbox node tree . The structure is like this .
I have been trying to construct a checkbox node tree . My specification is
I have been trying to implement a CheckBox Node Tree, where the parent nodes

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.