This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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!
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.
Joined: Apr 12, 2006
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.
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
Joined: Apr 12, 2006
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?
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.