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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:25:06+00:00 2026-05-17T17:25:06+00:00

I’m returning data via JSON and attempting to loop through the JSON dataset to

  • 0

I’m returning data via JSON and attempting to loop through the JSON dataset to dynamically populate a form. I need to reference a particular field TYPE (select, text, checkbox etc) via that field’s id attribute. The id attribute I’m matching against is coming through in the JSON columns. i.e. each column value in JSON corresponds to a form field’s ID attribute. Using that column value, I need to find out what its corresponding form field TYPE is so that I know how to handle the population of that field, i.e. if it’s a select box, the insert is different than for text fields, etc. This is what I have so far. It is populating the text fields just fine (because that doesn’t do a check on field type), but I need help accessing and populating checkboxes, selects, ckeditor, etc.

JSON

{"COLUMNS":["RECORD_ID","USER_ID","PRODUCT_NAME","MODEL_NUMBER","KEYWORDS","CATEGORIES","PRODUCT_GROUP_ID","DESCRIPTION","ORIGIN","SHIPPING_PORTS","MOQ","MOQ_UNIT","FOB_PRICE_CURRENCY","FOB_PRICE","LEAD_TIME","CAPACITY","CAPACITY_UNIT","SAMPLE_CURRENCY","SAMPLE_PRICE","SAMPLE_LEAD_TIME","PACKING","STANDARDS","SHIP_SINGLE","SINGLE_LEAD_TIME","PAYMENT_TERMS","SHOW_LIVE","MAKE_SELL_OFFER","RECEIVE_ALERTS","ALERT_KEYWORDS","BRAND_NAME","IMAGE1","IMAGE2","IMAGE3","IMAGE4","IMAGE5","IMAGE6","IMAGE7","IMAGE8","DOCUMENT1","DOCUMENT2","EXPIRY_DATE","CREATED_DATE","UPDATED_DATE","EXPIRED_FLAG","DISABLED"],"DATA":[[2,18,"Product Title "," * Model Number","Keywords","",17,"<p>\r\n\tsdadsafsasdasdasdasd<\/p>",0.0," \tShipping Ports","Minimum Order (MOQ)","Piece\/s","EUR","Please Enquire","MOQ Lead Time","Monthly Production Capacity","Piece\/s","EUR","Sample Price","Sample Lead Time","According to your requirements","Standards Compliance (e.g. cUPC, UPC, UL)",true,"Lead Time for single unit","L\/C,T\/T,D\/A",true,true,true,"bathroom vanities, bathroom mirrors, tiles, faucets",null,"17431~Sacred-Heart-of-Jesus-Posters.jpg","","","","","","","","","",null,"October, 09 2010 00:00:00","October, 13 2010 00:00:00",false,false]]}

jQUERY CODE

var product_id = $("#product_id").val();

$.getJSON("/cfcs/main.cfc?method=getProducts&returnformat=json",{"product_id":product_id},function(res,code) {
 //loop over each row
 for (i = 0; i < res.DATA.length; i++) {
  //loop over each column
  for (j = 0; j < res.DATA[i].length; j++) {
   var field = res.COLUMNS[j].toString().toLowerCase(); 
   var value = res.DATA[i][j].toString();
   // Here I want to check field type so I know how to insert data. But, I'm not sure how to go about it. Following is pretty much just pseudo code...

   if(field){    
    if (field.type == 'checkbox' && value == 1) {
     field.checked = true;
    }else if(field.type == 'select'){
     var options = $("#" + field).attr('options');
     if(options.length == 0){
      options[options.length] = new Option(value, field, true, true);
     }else{
      $("#" + field).val(value);
     }
    }else if(field.type == 'textarea'){
     CKEDITOR.instances[field].setData(value)
    }else {
     $("#" + field).val(value);
    }
   }
  }
 }
});
  • 1 1 Answer
  • 1 View
  • 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-05-17T17:25:06+00:00Added an answer on May 17, 2026 at 5:25 pm

    If field was an object, then you should be doing this:

    $('#' + field.id)...
    

    But as you are getting the value from JSON, it is a string. So you should be doing this:

    $('#' + field).attr('type')
    

    and not

    field.type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but

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.