Universally Related Popup Menus AJAX Edition: Part 3[con't]
We have to initialize
responseString to an empty string because we will be appending to it to create the response (line 43). Looping through a
recordset is quite easy to do. We just test for the
End Of File (
new Option at the end of the
options array. That position is denoted by the
movenext sets the cursor on the next record (line 50).
Before sending back the response string, we check for an error since we told the script to go ahead no matter what (line 53). If the
Err object has been populated, the error message is passed along to the AJAX
XmlHttpRequest object to display (line 54). Alternatively, if there are no list items for that parent ID, a value of "N/A" is returned to display in the list (line 56).
responseString is returned to the client's browser (line 60), and the objects are cleaned up (line 62).
For instance, the code that clears the list items is overzealous in its obliteration of all the list items. It would be more efficient to remove items only if there are leftovers remaining after the new ones have been created.
values could be changed for existing ones instead of creating new
Why not have default indexes for each list or even each linked URPM's list? That would allow each item of a list to result in a different default
listIndex in the child list. It sounds like a good idea, but it's a lot of work. I'll let someone else run with it!
The ASP code to call the proc could be better developed for multiple word names. As it stands, and ID of "kitchen sinks" would call a proc called "getKitchen sinks". Not bad, but it looks weird and the space could be a problem.
For homework, implement a caching system on the client-side to store previously-selected list items and their related lists. That would potentially eliminate some server calls if the user decided to go back to a previous selection.
I hope you enjoyed this installment of the URPMs. I think that you'll agree that AJAX was tailor made for this sort of application. Although I wrote the script pretty much from scratch, with the advent of frameworks like Struts and Spring, this type of thing is bound to get a lot easier in the years to come. Until then, AJAX remains a giant leap forward in the quest for a rich web user experience.
- DOM Events
- Linked Lists on Wikipedia
- Advanced Event Registration Models
- How to Create DOM Events
- Event Firing Order
- Stored Procedures In Access
- Synchronous vs. Asynchronous Processing Explained
- The Adovbs.inc Constants File
- The HTTP Charset Parameter
- The Response.Charset Property
- Charsets for Every Occasion
- Struts Framework
- Spring Framework
About the Author
Original: February 6, 2008