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
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
posted
0
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
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
posted
0
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
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
posted
0
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
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.