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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:33:27+00:00 2026-06-05T14:33:27+00:00

I need help with a loop… it’s probably simple but I’m having difficulty coding

  • 0

I need help with a loop… it’s probably simple but I’m having difficulty coding it up.

Basically, I need to check existing Ids for their number so I can create a unique id with a different number. They’re named like this: id=”poly’+i'” in sequence with my function where i is equal to the number of existing elements. Example: Array 1, Array 2, Array 3 corresponding with i=1 for the creation of Array 1, i=2 for Array 2, etc.

Right now i is based on the total number of existing elements, and my “CreateNew” function is driven off x=i+1 (so the example above, the new element will be named Array 4). The problem is that if you delete one of the middle numbers, the “Create” function will duplicate the high number. i.e. Array 1, 2, 3 delete 2, create new-> Array 1, 3, 3.

I need an if() statement to check if the array already exists then a for() loop to cycle through all i’s until it validates. Not sure how to code this up.

The code I’m trying to correct is below (note I did not write this originally, I’m simply trying to correct it with my minimal JS skills):

function NewPanel() {


  var i = numberOfPanels.toString();
  var x = (parseInt(i)+1).toString(); 


  $('#items').append('<div onclick="polygonNameSelected(event)" class="polygonName" id="poly'+i+'">&nbsp;&nbsp;Array '+ x +' &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="removePolygon('+i+');return false;">&nbsp;&nbsp;&nbsp;</a></div>');
  $('div[id*=poly]').removeClass('selected');
  $('#poly'+i).addClass('selected');
  $('#poly'+i).click(function() {
    selectedPolygon = i;
    $('div[id*=poly]').removeClass('selected');
    $(this).addClass('selected');
  });

}

THANK YOU! 🙂

  • 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-05T14:33:30+00:00Added an answer on June 5, 2026 at 2:33 pm

    Please clarify “The problem is that if you delete one of the middle numbers, “. What do you mean by delete? Anyway, the simplest solution is to create two arrays. Both arrays will have the same created id’s. Whenever an id is created in the first array, an id will be added to the second array. So when it is deleted from first array, check your second array’s highest value and then create this id in first array. I hope this did not confuse you.

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

Sidebar

Related Questions

I need help building a loop in my stored procedure, basically i want it
I need some help with an array and a foreach loop, I have an
I need help making this loop to move a label move smoothly across the
I need help refactoring this multi-loop thing. Here is what I have: Campaign has_many
Need to store values from foreach loop into an array, need help doing that.
I need help with some programming logic... I need to loop this method to
I need help with my loop. In each div, I want to show two
I need help with this loop through an array. Right now I have 3
Hi all I need help I want to loop trough the all cells in
i need help for this task. i need a for loop who picks the

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.