File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Travis Hein
Ranch Hand
Posts: 161
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much .

What you said is absolutely right .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic