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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:05:19+00:00 2026-06-02T15:05:19+00:00

This is my JavaScript code: // action when item file is clicked $(li span.file).click(function(){

  • 0

This is my JavaScript code:

// action when item file is clicked
$("li span.file").click(function(){

    // get the ID
    console.log($(this).attr('id'));

    $.getJSON('BomItemToJSON', function(data) {
        $.each(data, function(i, item) {
            var id = item.id;
            var description = item.description;

            formObject = document.forms['itemForm'];
            formObject.elements['itemId'].value = id;
            formObject.elements['itemDescription'].value = description;
        });
    });

});

This is a part of my servlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        utx.begin();

        BomHandling bh = new BomHandling(em, utx);

        BomItem item = bh.getBomItem(63788);
        Gson gson = new Gson();
        String json = gson.toJson(item);

        System.out.println("Json: " + json);

        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(json);
        utx.commit();
    }

It returns:

Json: {"itemId":63788,"modules":[],"deprecated":false,"partNumber":"SG-XPCIE8SAS-E-Z","description":"4 GB Memory Expansion (2 x 2GB) low-profile FBDIMMs, Gen 2, 1.8 V, for Sun SPARC Enterprise, RoHS 6. (For Factory Integration Only)","quantity":0,"unitPriceDollar":"$350.00","discount":"10%","totalDollar":"$0.00","itemClass":"Server","itemType":"HW","vendor":"Sun"}

From the console log I know that this servlet is called:

[09:22:11.633] GET http://localhost:8084/xxx/BomItemToJSON [HTTP/1.1 200 OK 80ms]

This is my form:

<div id="itemdetail">
    <form name="itemForm">
        ID: <input type="text" name="itemId" value="" size="100"></input>
        Description: <input type="text" name="itemDescription" value="" size="100"></input>
    </form>
</div>

How can I insert the itemId and the description from the JSON object into my form? Right now it is always ‘undefined’.

  • 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-02T15:05:20+00:00Added an answer on June 2, 2026 at 3:05 pm

    You don’t need the each. Your JSON is only a single object, not an array.

    Your code should be like this I think:

    // action when item file is clicked
    $("li span.file").click(function(){
    
        // get the ID
        console.log($(this).attr('id'));
    
        $.getJSON('BomItemToJSON', function(data) {
            alert('entered getJSON()');
            var id = data.itemId;
            var description = data.description;
    
            alert('description: ' + description);
    
            formObject = document.forms['itemForm'];
            formObject.elements['itemId'].value = id;
            formObject.elements['itemDescription'].value = description;
    
            alert('done with javascript');
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: <script language=javascript type=text/javascript> $(document).ready(function(){ $('.tree div').click(function(){ var id = $(this).attr('id');
I have this javascript code <Script> function getGroupId(){ var group=document.getElementById(selectedOptions).value; var groupFirstLetter=group.substring(2); } </Script>
This is my JavaScript code: <script> function change(name){ var element = document.all.name.value; } </script>
I had the following in the <head> of a GSP <script type=text/javascript> $(button.remove-item).click(function() {
This javascript code does not work in IE8, but works in Firefox and Google
i have this javascript code to which i want to add the jquery fade-in
I have this javascript code below that uses jquery, it is suppoed to be
I have this JavaScript code: for (var idx in data) { var row =
How to write this JavaScript code without eval? var typeOfString = eval(typeof + that.modules[modName].varName);
I have this JavaScript code that creates a table, and puts in the rows

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.