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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:48:44+00:00 2026-06-17T06:48:44+00:00

I am dynamically generating the checkboxes as follows: entries.each(function() { if($(this).find(‘parentcategoryid’).text() == 0) {

  • 0

I am dynamically generating the checkboxes as follows:

entries.each(function()
{
    if($(this).find('parentcategoryid').text() == 0)                
    {
        xmlArr += '<span><input type="checkbox" data-mini="true" name="category'+$(this).find('categoryid').text()+'" id="checkbox'+$(this).find('categoryid').text()+'" class="techAreasCheckBox" style="margin-top: 5px;"/><label class="techAreasLabel">'+$(this).find('categoryname').text()+'</label></span><br>'; 
    } 
    else
    {
        xmlArr;
    }                   
}); // Entries.Each function

say the names of the checkboxes generated are as follows: category1, category2, category3, category8, category10, category54, category55, category56, category, 59, category62, category132, category133.

Also, I have an array of 4 numbers: 2, 54, 8, 10….

I want to check the checkboxes having name attribute ending with these numbers in array. How shall I proceed?

Note: These are DYNAMICALLY GENERATED Checkboxes.

  • 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-17T06:48:45+00:00Added an answer on June 17, 2026 at 6:48 am

    To check the checkboxes, all you need to do is add the checked attribute as described here.

    Below is one solution. First, you want to store the Id instead of looking it up every time because it’s faster. Second, I used the $.inArray function to determine if the category is in the array that contains the numbers that should be checked. Finally, I used a ternary to add the checked attribute.

    var numberArray = [2, 54, 8, 10];
    
    entries.each(function() {
         if($(this).find('parentcategoryid').text() == 0) {
              var categoryId = $(this).find('categoryid').text();
              var categoryInArray = $.inArray(categoryId, numberArray) !== -1;
    
              xmlArr += '<span><input type="checkbox" data-mini="true" name="category'+categoryId+'" id="checkbox'+categoryId+'" class="techAreasCheckBox" style="margin-top: 5px;"' + categoryInArray ? ' checked="checked" ' : '""/><label class="techAreasLabel">'+$(this).find('categoryname').text()+'</label></span><br/>'; 
         }
    }); // Entries.Each function
    

    Alternatively you can just use another if statement.

    entries.each(function() {
         if($(this).find('parentcategoryid').text() == 0) {
              var categoryId = $(this).find('categoryid').text();
              var categoryInArray = $.inArray(categoryId, numberArray) !== -1;
    
              if(categoryInArray) {
              xmlArr += '<span><input type="checkbox" data-mini="true" name="category'+categoryId+'" id="checkbox'+categoryId+'" class="techAreasCheckBox" style="margin-top: 5px;" checked="checked"/><label class="techAreasLabel">'+$(this).find('categoryname').text()+'</label></span><br/>'; 
              } else {
              xmlArr += '<span><input type="checkbox" data-mini="true" name="category'+categoryId+'" id="checkbox'+categoryId+'" class="techAreasCheckBox" style="margin-top: 5px;"/><label class="techAreasLabel">'+$(this).find('categoryname').text()+'</label></span><br/>'; 
              }
         }
    }); // Entries.Each function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am dynamically generating a function and assigning it to a class. This is
I am dynamically generating checkboxes with id like chkBox100 etc and with onClick function.
I'm generating buttons dynamically that I want it to call a method like this:
How could one go about dynamically generating a shape like this in CSS3: Ignore
I'm dynamically generating a list of checkboxes based on the contents of json data:
I am dynamically generating some radio buttons like this: degree_info.innerHTML += '<label for=radio>Current Work:</label>\
I have one asp.net grid view. This rows and columns are dynamically generating based
I want to validate Checkbox in javascript, checkboxes is generating dynamically by PHP and
I am dynamically generating a div and want to change its content via html()/text(),
I have a block of text I am dynamically generating. It is about two

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.