my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Three dropdowns, dependent, almost working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Three dropdowns, dependent, almost working" Watch "Three dropdowns, dependent, almost working" New topic
Author

Three dropdowns, dependent, almost working

stephen r davidson
Ranch Hand

Joined: Jun 23, 2013
Posts: 58
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?

:-


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
stephen r davidson
Ranch Hand

Joined: Jun 23, 2013
Posts: 58
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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

Joined: Jun 23, 2013
Posts: 58
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

Joined: Jun 23, 2013
Posts: 58
and thanks!
stephen r davidson
Ranch Hand

Joined: Jun 23, 2013
Posts: 58

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

Joined: Jun 23, 2013
Posts: 58
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Either fetch the form markup via Ajax, or build it using JavaScript.
stephen r davidson
Ranch Hand

Joined: Jun 23, 2013
Posts: 58
Thanks Bear....Do you have any insight into the question posed in my previous reply?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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

Joined: Jun 23, 2013
Posts: 58
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

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

Joined: Jun 23, 2013
Posts: 58
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

stephen, your post was moved to a new topic. Please be sure to start new topics for new questions.
 
Consider Paul's rocket mass heater.
 
subject: Three dropdowns, dependent, almost working