• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • 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 .
 
Ranch Hand
Posts: 161
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much .

What you said is absolutely right .
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!