File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes How to fill up  JSONArray data inside the select tag of JSP Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to fill up  JSONArray data inside the select tag of JSP Page" Watch "How to fill up  JSONArray data inside the select tag of JSP Page" New topic
Author

How to fill up JSONArray data inside the select tag of JSP Page

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I am using AJAX and JSONArray .
This is my requirement . I am having two select tags inside my jsp page . one for country and one for state .Upon selecting a country the select tag for states should be filled up .


In my jsp page , on body onload i am trying to get the data from DataBase and fill up the country select Tag .For this on body onload i am calling my servlet to get the countries list and keeping it in my JSONArray.


Please let me know inside my callback functionality in ajax how can i put this data inside my select option values .

Save India From Corruption - Anna Hazare.
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
I think, instead of wrapping the JSON response inside a <countries></countries> xml tag, just have this service return the JSON string of the array contents as type application/json

so the ajax client side that invokes this url will receive an array of just of the 1 value country here, we need to do some javascript work to eval the JSON array into a javascript var
(this depends on what javascript toolkit you are using)

and then use a for loop to go over each item in this array and populate object tags within the select field.




Error: Keyboard not attached. Press F1 to continue.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you very much .

What you said is absolutely right .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to fill up JSONArray data inside the select tag of JSP Page