• 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

Drop Down Menu Using AJAX and JSP

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
New to this site, nice stuff you have going here,
I would like to ask for some help with JSP and AJAX, I'm new to that too ;-)
I have a JSP web form with combo boxes,
the combo boxes should be populated with the names from a database table,
I'm cool with connecting to the Database and getting the names, not a problem,
but the real problem I've got is the AJAX to load the names in there and in what form to return the names gathered from the query. I understand there will need to be some form of HTP request and receive statement. but beyond that.. I'm a touch lost
Also the examples that I have seen all seem to have the database connection on the client end... but to my understanding isn't that poor practice?
could someone help me out please? I would really appreciate some very small example that I can sift through and code out myself to see the flow etc!


thanks guys
 
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
The technology you seek is indeed Ajax, and it's a JavaScript thing.

By the time your page gets to the browser, it's just an HTML page with JavaScript so I'm moving this to the HTML/JavaScript forum as it's not really a JSP question.
 
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
First thing: HtmlHasNoComboBox -- correct terminology is important!

Now, what you need to do is:
  • Establish a change handler on the first dropdown to detect when it is changed.
  • In the handler, grab the selected value and issue an Ajax request to fetch the set of options for the 2nd dropdown.
  • In the Ajax success handler, take the response (the HTML fragment of options), and tack it onto the 2nd dropdown.

  • Ajax is much much easier if you use a JavaScript library such as jQuery, which turns the above into a few lines of code. (In raw JavaScript it's like about 3 dozen or so.)
     
    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
    One more thing...

    Robert Merrett wrote:Also the examples that I have seen all seem to have the database connection on the client end... but to my understanding isn't that poor practice?


    If by this you mean that the examples had the DB code in the JSP, that's not client-side as the JSP is evaluated on the server in order to create the HTML output that will be sent to the browser.

    But regardless of that, yes, it's a horribly poor practice to put Java code -- especially DB code -- into a JSP.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic