• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Three dropdowns, dependent, almost working

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to modify sample code to work in my environment. I have had a measure of success, but hitting a snag. Here is the code..



I have created a context attribute that populates dropdown number 1. However, when I click on a value in dropdown 1, and step through the javascript on mizilla, I get this line:

$.getJSON(jsonURL, function(opts) < --------------

then it drops to the end of the function.

The servlet is defined in web.xml as shown here:



I have breakpoints set in the servlet code. But they don't get hit.

Any suggestions?

:-


 
Sheriff
Posts: 67637
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

stephen r davidson wrote:then it drops to the end of the function.


Well, yeah. Ajax is asynchronous. The success callback isn't going to fire until the response is returned.

Try setting breakpoints in the callback. If they're not being hit, then your Ajax is failing. Use the debugger to find out why.
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The sample I am following says to code this in my servlet:



Is this the callback that you are referring to? At any rate, I DO set breakpoints, but they are never tripped. Perhaps this sample is not valid? Learning. inch by inch.
 
Bear Bibeault
Sheriff
Posts: 67637
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
No. The callback is the function that you are passing to the $.geJtson method.

If the servlet is never being invokde, it's likely that the request is failing. Look at the network section of the JavaScript debugger in the browser for clues.
 
Bear Bibeault
Sheriff
Posts: 67637
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
P.S. The fact that the URL you are using for the Ajax does not start with the context path is very suspect.
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
It did, then didn't, then I plugged in http://localhost:8080/context/servler and...
it worked.

Cool.

One step closer to nirvana....

:-
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and thanks!
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The following works as I want it to work on Mozilla22....But troubles on other browsers. In IE8 and 9 I get a message indicating it doesn't like the method at this line:
if ($('#' + parentId + ' :selected').val().contains('chooseeventtype')){
Can someone suggest an alternative?

 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the end result of this effort is, three dropdowns. Upon change of the last dropdown, I want to use the values of the three dropdowns on the server to build a dynamic html form. Sort of like I used to do using out.print from a servlet. Is this a good idea? Bad idea?
So upon change of the last dropdown, I would like a form to appear under the dropdowns. Just looking for some assurances before I get started.
 
Bear Bibeault
Sheriff
Posts: 67637
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
Either fetch the form markup via Ajax, or build it using JavaScript.
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear....Do you have any insight into the question posed in my previous reply?
 
Bear Bibeault
Sheriff
Posts: 67637
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
I thought I did. But perhaps you could expand upon the nature of the form that appears? Is us static regardless of what is chosen? Is it built based upon the choices? If so, how?
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You actually DID respond on that one. It is this one that I wanted your input on. :-)


stephen r davidson wrote:
The following works as I want it to work on Mozilla22....But troubles on other browsers. In IE8 and 9 I get a message indicating it doesn't like the method at this line:
if ($('#' + parentId + ' :selected').val().contains('chooseeventtype')){
Can someone suggest an alternative?

 
Bear Bibeault
Sheriff
Posts: 67637
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
Hmm, just musing, contains() is a fairly new addition to JavaScript, IE may not support it yet. I don't have a Windows VM handy at the moment to check. I'd give indexOf() a try.
 
stephen r davidson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I click on the third dropdown and choose an entry, the getColumns script gets the data from the servlet. I can see that the data is there in the callback. But I don't ever get any table rows added to my existing #display table. Anyone see why?

 
Bear Bibeault
Sheriff
Posts: 67637
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
stephen, your post was moved to a new topic. Please be sure to start new topics for new questions.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic