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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:08:00+00:00 2026-06-05T07:08:00+00:00

I keep having issues iterating over some JSON to put in select options (btw,

  • 0

I keep having issues iterating over some JSON to put in select options
(btw, ignore the actual values for “label”, those are garbage atm).

Here is an example that my php is passing into this:

[{"value":"1","label":"04-22-12"},{"value":"4","label":"04\/04\/12"}]

I am currently trying this loop:
*note, dateSelect is defined somewhere else

for (res in JSON.parse(request.responseText)) {
    var date = document.createElement("option");
    date.value = res.value;
    date.text = res.label;
    dateSelect.add(date, null);
}

However, it is adding “undefined” into my options…
How do I get it so each value and corresponding label is put in there correctly?

  • 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-05T07:08:01+00:00Added an answer on June 5, 2026 at 7:08 am

    You have an Array, so don’t for-in.

    In your code, res is the property name (the index of the Array in this case) in the form of a string, so the properties you’re looking for aren’t going to be defined on the string.

    Do it like this…

    for (var i = 0, parsed = JSON.parse(request.responseText); i < parsed.length; i++) {
        var res = parsed[i];
        var date = document.createElement("option");
        date.value = res.value;
        date.text = res.label;
        dateSelect.add(date, null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some issues trying to keep the state of values in textbox controls
I'm having some issues filling a list in Python. I keep getting a list
I am having some issues with my code, and keep getting the same error,
Having issues with dynamically creating <select> tags and then populating them with XML values.
So I am having some issues with some NA values in the residuals of
ok, im having some syntax issues that keep evading me. :( one is at
I am on my transitional trip from MATLAB to scipy(+numpy)+matplotlib. I keep having issues
I am having issues with my software. In my piano software if I keep
We keep having some customers getting a warning from AVG Antivirus about our application.
I'm having issues gathering data using JSON on the Songkick API. I'm really new

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.