• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ajax drop down

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends ,

interesting question to all experts out there, I have one drop down and when user clicks i need to get data using ajax with java classes. but how to load data using ajax and place that using specific format.

the structure is using Ajax, JSON and JAvascript

- any help is much appreciated
- thanks
 
Sheriff
Posts: 67746
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
What do you have coded so far?
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chintan ramavat:
Hello friends ,

interesting question to all experts out there, I have one drop down and when user clicks i need to get data using ajax with java classes. but how to load data using ajax and place that using specific format.

the structure is using Ajax, JSON and JAvascript

- any help is much appreciated
- thanks



Chintan,

Are you attempting to populate the contents of a second <SELECT> element based on input from the first? This is commonly referred to as a chained selector.

You cannot do this with only Javascript (note: AJAX and JSON are not programming languages. AJAX refers to a methodology, and JSON is a data format in the same way as XML is). You need a Java class to do this on the server side. I tend to use a struts action to do it. You may also wish to take a look at json-lib (http://json-lib.sourceforge.net), which converts Collections, Maps, and individual objects to JSON.

I also have a chained selector javascript function, which relies on the Prototype javascript library. Let me know if you are interested.

Jason
 
Bear Bibeault
Sheriff
Posts: 67746
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

Originally posted by Jason Ferguson:
You need a Java class to do this on the server side.

Not necessarily. Firstly, we're not even sure that dependent drop-downs are what the OP is referring to. Secondly, if the data set is small and relatively semantic-free, its perfectly possible to handle this with a series of static text files on the server. Moreover, even if server-side assistance is required, there are more choices than just Java (php, cgi, etc).

The OP does specify Java, but for others that might be wanting to set up similar mechanisms, Java is not the only choice.
[ February 24, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jason,
I used Prototype.js to build this chained selector. My flow is basically like this:

Initially in my jsp only one drop down will have values and the other will be disabled. Onchange of first dropdown i do an ajax call which calls my servlet. The servlet queries the database based on the parameter sent to it
and returns a delimited string as response.

Again, back in responsetext in ajax, i use string.split method to convert that delimited string to javascript array and populate the options of the second dropdown.

Before that, i remove all the existing options in the second dropdown before populating the fresh data.

This is working fine. But when i test it by changing the selection in the first dropdown, after say, 4 or 5 selections, the application slows down and is hanging. It says, a script is causing it to run slowly. please stop running the script.

What could be the reason? Here is the javascript function which gets the response from the servlet

Note :grpElement is the name of my second drop down list

 
Bear Bibeault
Sheriff
Posts: 67746
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

Originally posted by Kalai Selvi:
It says, a script is causing it to run slowly. please stop running the script.

This usually means that your script has entered an infinite loop.

Carefully reconsider the following code:
 
Kalai Selvi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help.

Actually that piece of code was getting into an infinite loop.
I changed my code to



It is working fine now.


Kalai Selvi
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,
Even I have the same question i.e,
I have 2 drop down boxes and this drop down will have values and the other will be disabled. Onchange of first dropdown i need to do an ajax call which calls my servlet. The servlet queries the database based on the parameter sent to it and returns values which become the values of the 2nd drop down box.I need the complete working code for this.
I dont want structs,I need simple code involving JSP,Java Scripts,Ajax and servlets.PLease help me.
This is a critical requirement which I'm trying to solve form the past 2 months.I got php with Ajax code with this,but I dont want that...
I need Ajax with servlets.
Please reply and help me as soon as pujaa26@yahoo.co.in possible.
My Email Id pujaa26@yahoo.co.in
 
Bear Bibeault
Sheriff
Posts: 67746
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
[Edit: thread hijack removed. Please start your own questions in a new topic]
 
reply
    Bookmark Topic Watch Topic
  • New Topic