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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:47:57+00:00 2026-06-07T02:47:57+00:00

I have 2 arrays, one with cities, and another array with ID’s… I would

  • 0

I have 2 arrays, one with cities, and another array with ID’s…
I would like to loop both, and then output some HTML

Right now im only looping cities, and then appending some HTML to a as following:

if ($jq(".area").length > 0) {

    var region = $jq(".hiddenFieldRegion").val();
    var cityIDs = $jq(".hiddenFieldChosenAreas").val();
    var strcities = $jq(".hiddenFieldChosenCities").val();
    //var cities = strcities.split('|');

    //Set region to be marked
    if (region) {
        $jq(".mapdk").attr("class", region);
    }

    //Appending to searchform
    if (strcities) {
        $jq.each(strcities.toString().split("|"), function (k, v) {
            var v = v.split("|");
            $jq("<option selected />").text(v[0]).appendTo("select.chosen-cities");
        });
    }

}

I would like the place where im appending to the searchform, add an attribute value, with an ID from the cityIDs array…

So i get some HTML like:

<option value="XXX">CityName</option>

Is that possible?

  • 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-07T02:47:59+00:00Added an answer on June 7, 2026 at 2:47 am

    Assuming your cities IDs and your cities names are orderred in the same way, you can access each name/id by this index in the arrays :

    var cityIDs = $jq(".hiddenFieldChosenAreas").val();
    var strcities = $jq(".hiddenFieldChosenCities").val();
    
    var cityIDs_array = cityIds.split("|");
    var strcities_array = strcities.split("|");
    
    ....
    
    if (strcities) {
        $jq.each(strcities_array, function (k, v) {
            //var v = v.split("|"); Unnecessary if strcities is like "city1|city2|city3"
            $jq("<option value='"+cityIDs_array[k]+"' />").text(v).appendTo("select.chosen-cities");
        });
    }
    

    In this, way, you can access each city ID in your loop.
    But I think you should store city name and city id in the same string. For example "city1:1|city2:2|city3:3". Then, with some use of split function, you’ll get id and name.

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

Sidebar

Related Questions

I have 2 arrays - one array is coming from the database, another from
Android: I have two byte arrays one byte array of bitmap and another byte
I have two arrays the first one has this structure Parameter Keys array array
I have some Javascript code that creates 2 arrays: One for Product Category and
I have two arrays. I'd like to copy ranges of data from one of
I have two arrays. I'd like to merge them into one, but remove the
I have two arrays one with OS's such as Ubuntu and Windows and another
I have two arrays of objects. I would like iterate over each of these
I have two arrays one with fake Japanese characters, another with the English alphabet
I have two arrays one is for names and another is for phone numbers,and

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.