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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:14:31+00:00 2026-06-03T17:14:31+00:00

I want to create a dynamic select input (dropdown menu) from JSON. I have

  • 0

I want to create a dynamic select input (dropdown menu) from JSON.

I have tried two approaches to getting a JSON object for a dropdown menu Select input (which I have labeled Attempt 1 and Attempt 2 in the commented out JS).

I have the string returning to the client, however, the front end is not seeing it as a JSON object, but rather just a string. I have tried to parse and serialize it using both the .Net serializer and the Json2 Parse.

AJAX Call

function getcategories(categoryId) {

    $.ajax({
        type: 'POST',
        url: '/Services/Category.aspx/GetCategory',
        data: '{"categoryId":"' + categoryId + '"}',
        contentType: 'application/json; charset=utf-8',
        global: false,
        async: false,
        dataType: 'json',
        success: function (msg) {
            if (msg.d == null || msg.d == '') {
                //end of the road. not more categories. so don't add another DDL
                jsonList = '';
                console.log("No more DDLs: ");
            } else {
                //attempt 1: converting returned data to Json
                //var json = JSON.parse(msg.d);//just returns [object object]
                //jsonList = json.d;
                //attemp2: trying to consume stringbuilder string as Json
                //or if I do the below, I also get an error Table does not exist
                //jsonList = msg.d
            }
        }

    });
    return false;

}

Returned JSON

{
    "Table": [{
        "categoryid": "0",
        "categoryname": "--Select Category1--"
    }, {
        "categoryid": "2",
        "categoryname": "subname2"
    }, {
        "categoryid": "3",
        "categoryname": "subname3"
    }, {
        "categoryid": "4",
        "categoryname": "subname4"
    }]
}

Trying to use it in a loop here:

//simplified function inside the ready()
//add dynamic select with options from Json
$('<select id ="DDL' + nextSelect + '" class="cascade"><option value="-">-- Step' + nextSelect + ' --</option></select>').appendTo('div .chooseSteps');
console.log("Obj " + categoryJson); //shows the Json string 
console.log("TABLE " + categoryJson.Table); //returns undefined :(
var listItems = "";

//Says that Table does not exist (undefined)
for (var i = 0; i < categoryJson.Table.length; i++) {
    listItems += "<option value='" + categoryJson.Table[i].categoryid + "'>" + categoryJson.Table[i].categoryname + "</option>";
}

So my goal is to get the options to display and get the values of Table.

I searched the forum all afternoon, and could not find a solution that worked, and this is driving me crazy. Thanks for your understanding.

I am using jQuery 1.7.1 AJAX with Json2.js (as a backup for older browsers) with Asp.Net 4.

  • 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-03T17:14:32+00:00Added an answer on June 3, 2026 at 5:14 pm

    Your response doesn’t have a d property.

    Don’t try to parse it. jQuery does that.

    Just do this:

    jsonList = msg.Table
    

    Although I don’t see where you’re transitioning from the AJAX call to the code at the bottom, so I’m not sure what’s happening in between.

    These suggest the JSON isn’t parsed:

    console.log("Obj " + categoryJson); //shows the Json string 
    console.log("TABLE " + categoryJson.Table); //returns undefined :(
    

    So right here you would need to $.parseJSON it. Again, I see no relationship between the two code examples.

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

Sidebar

Related Questions

I have less experience with Java Swing and I want to create a dynamic
I want to create PayPal button with dynamic price (depending from the item) and
I want to know how to create dynamic table in mySql . I have
I have a website and I want to create a dynamic sitemap for it.
I want to create dynamic tabPages in TabControl. In each tabPage I create dataGridView
I want to create dynamic number of thread which is depends on the database
I want to create a Dynamic aspx Page in current solution through code-behind..forexample i
I want to create a dynamic Expression<Func<T,Y>> . Here is the code which works
this table i want to create job_id dynamic Jobs Title text Job Description text
I want to be able to create links looking like buttons with dynamic text

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.