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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:23:07+00:00 2026-06-17T23:23:07+00:00

I am using a JSON object something like this {expiry_year:15,number:411111,month:12,cvn:456} Now on some callback

  • 0

I am using a JSON object something like this {"expiry_year":"15","number":"411111","month":"12","cvn":"456"}

Now on some callback I am getting this value. My requirement is to put these values in a from by using MAP so in future if some one change DOM id it won’t affect the page.

To achieve this I am trying like this

var domWithValueMap = {
              "number" : "number",
              "cnv" : "cnv",
              "month" : "expiry_month",
              "expiry_year" : "expiry_year"
          }

In above hash

var domWithValueMap = {
              "keys of json obg" : "id of DOM",

          }

and so on..

My div id’s are : number,expiry_year,month and cvn.

Then after I was trying to match whether the keys are exists or not using this

   domWithValueMap.hasOwnProperty(key);

After this I gets confused how to proceed. Please help me to achieve this.

  • 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-17T23:23:08+00:00Added an answer on June 17, 2026 at 11:23 pm

    This should do the trick:

    var values = {"expiry_year":"15","number":"411111","month":"12","cvn":"456"};
    for(var key in values){
        document.getElementById(domWithValueMap[key]).value = values[key];
    }
    

    A little longer, with comments:

    var values = {"expiry_year":"15","number":"411111","month":"12","cvn":"456"};
    for(var key in values){                       // Loop through your values,
        var id = domWithValueMap[key]             // Get the element ID from the value's key,
        var element = document.getElementById(id) // Get the element,
        element.value = values[key];              // Set teh value of the element.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build nested json object using python jsonpickle, something like this {key:
I need to populate a json file, now I have something like this: {element:{id:10,quantity:1}}
I am using jquery to loop through json object... But some how it doesn't
I'm creating a JSON object like tags = {jon:[beef,pork],jane:[chicken,lamb]}; which was generated using php
I have JSON object inside variable like this: var chessPieces = { p-w-1 :
I am using json decode to get some array back. the returned object looks
I have a json structure that looks something like this: list:[ { type:link, href:http://google.com
right now I'm creating an array and using: render :json => @comments This would
I have some JSON that is sent to my webservice that looks something like
I am using jquery ajax($.ajax) method to get a json object from c# webmethod.This

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.