• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

JSON Object and Java Script DropDown

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to populate a dropdown box using JSON response from a Portlet.Help me with a code.

How can I do it with JSONObject,to contain all those options and its values.

Help me with a code.

Thanks
Ashok
 
Sheriff
Posts: 67554
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You first. What have you written so far? Where is it giving you problems? What is the format of your JSON? If you haven't designed it yet, what kind of data do you think it should contain?

Show some effort.
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i created some thing like this.

import net.sf.json.JSONObject;

JSONObject json = new JSONObject();
json.put("key", title);
json.put("value", developer);


I need to add multiple objects to populate in JSP as a Dropdown.

Thanks
Ashok
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And are you doing this with Ajax? Have you done a basic tutorial on how to make an Ajax call?

Eric
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing AJAX on liferay portal and I am trying to create JSONOBject from my databean on server side and send it to client , parse it, iterate and display on another dropdown.
I am trying to figure out 2 issues
1. how to create JSON on server side from bean.
2. How to parse and iterate it on client side

Thansk for help
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well parsing it is easy if you are able to use a library such as jQuery



if you are not using a library you need to use something like json.js or eval

Than you can add options to your select using new Option

Eric
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply,

Sorry i missed to mention that I am using dojo for making server call via dojo.io.bind(.., that gets json from server, I am new to dojo so I am trying to find the dojo parser,
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://geochalkboard.wordpress.com/2009/08/03/reading-json-data-with-dojo/

Eric
 
Ashok Periaswamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used JSON.parse and got the parse done. I will proceed to create options, Thanks for help
 
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic