permaculture playing cards*
The moose likes HTML, CSS and JavaScript and the fly likes jQuery execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jQuery execution" Watch "jQuery execution" New topic
Author

jQuery execution

William Rouse
Ranch Hand

Joined: Apr 12, 2006
Posts: 73
Below is the source listing of a tutorial on construction sequential parts of a form using jQuery. In studying the tutorial I realized that there is a significant non understanding that I have of jQuery. The problem is the appearance and disappearance of the next and previous prompts in the first and last section of displaying the form. When I step through the code with a debugger, the debugger never hits either of these two functions,

yet the proper prompts appear. Can someone explain this? Thanks!
WBR



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

William Rouse wrote:When I step through the code with a debugger, the debugger never hits either of these two functions

The two lines you show are part of the document-ready handler and cannot possibly not be called. I suspect your debugger isn't getting control until after they have executed.
William Rouse
Ranch Hand

Joined: Apr 12, 2006
Posts: 73
After the page is plotted and someone is filling in the form on the second section, and then either moves forward to the third page, or backward to the first page, should not one of these functions be executed.
WBR
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why can't they be called? If I set a breakpoint on the remove() lines the breakpoint is hit (FF/Firebug).

It's working for me (although I'd argue against doing it like this).
William Rouse
Ranch Hand

Joined: Apr 12, 2006
Posts: 73
I'm using the javascript debugger in Netbeans and I don't see it. I'll try learning enough of Firebug later and try it.
David Newton, how would you go about it?
Thanks!
WBR
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Considering the low number of inputs I'd just put it all on one page. If there was some compelling reason to break it up I'd just use new pages. I don't feel the JS hide/show functionality adds anything.

If I *was* going to do it like this I'd figure out some way to make it less brittle. Seeing things like "$(this).parent().parent().hide().next().show();" tells me that it'll break at some point from an unrelated structural change--and if the person fixing it isn't the person that wrote it they'll be sad.

Oh, and always use "for" attributes on label tags :p
William Rouse
Ranch Hand

Joined: Apr 12, 2006
Posts: 73
This is just a tutorial someone presented to show a concept and I learned from it.
I don't understand though, David what you mean by "label tags :p", where in the code is that?
Thanks!
WBR
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

I'm going to agree and disagree with David.

I prefer clarity over cleverness, so yeah, I wouldn't do things exactly this way. But this is from a tutorial where often "cleverness" is used just to get a concept across. Out of context, it's hard to tell.

I would not discount using dynamic elements, but again, I'd do it in a clearer fashion than is done here.

Also, the mere presence of long chains of jQuery commands isn't an issue -- in fact, it's one of jQuery's great strengths. But yes, I'd do things in a less fragile fashion. Long command chains aren't something to be avoided; just something to be sure to do well.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

William Rouse wrote:what you mean by "label tags :p", where in the code is that?

There are label tags in the HTML markup. Some have for attributes, but some do not.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not against train wrecks, but (largely) structural ones give me the willies. Being Smalltalkish I'm a big fan of chaining :)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

David Newton wrote:but (largely) structural ones give me the willies.

Agreed. Too fragile for my tastes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jQuery execution