Meaningless Drivel is fun!*
The moose likes HTML, CSS and JavaScript and the fly likes JSON Object and Java Script DropDown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JSON Object and Java Script DropDown" Watch "JSON Object and Java Script DropDown" New topic
Author

JSON Object and Java Script DropDown

Ashok Periaswamy
Greenhorn

Joined: Feb 16, 2003
Posts: 5
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ashok Periaswamy
Greenhorn

Joined: Feb 16, 2003
Posts: 5
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
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
And are you doing this with Ajax? Have you done a basic tutorial on how to make an Ajax call?

Eric
Ashok Periaswamy
Greenhorn

Joined: Feb 16, 2003
Posts: 5
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Feb 16, 2003
Posts: 5
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
http://geochalkboard.wordpress.com/2009/08/03/reading-json-data-with-dojo/

Eric
Ashok Periaswamy
Greenhorn

Joined: Feb 16, 2003
Posts: 5
I used JSON.parse and got the parse done. I will proceed to create options, Thanks for help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSON Object and Java Script DropDown
 
Similar Threads
JSON+Jquery
How to set value to session in external js file
selection box problem
Dynamic Population of Drop Down List using AJAX
JSON response to populate listbox