tags:

views:

25

answers:

1

I have a page ItemList that shows a list of items using div's. After adding an item page would be redirected to the ItemList page. At this point I want to add the fade in/out effect for the newly added item (which should be the last div). But how do I determine if the user just added an item and came to this page, or they're directly visiting this page? Or are there better ways to do what I'm doing? Thanks.

+2  A: 

The typical approach would be to do your add directly from the list page (perhaps you click an "Add" link and get a modal jqueryui dialog), and when you submit that dialog, both the actual add and the list update happen via AJAX (and when the list is updated via AJAX, the fade effect is used for the new item).

If you're not using AJAX, I think your best bet would be this: on the server side, the first time you build the list after adding a new item, you add a special class to that last div. Then you have jQuery check for that class and do the fade. How you know on the server side whether a particular item has just been added depends on what technology you're using on the server side; but in a generic way, when a new value is submitted, you do your add, you put the ID of the newly added item into the request attributes or into the session, and then when you redirect to the list page you check for that attribute.

JacobM
Thanks, what about when you're not using AJAX?
redbluegreen
Added a suggestion for a non-ajax approach.
JacobM
Thanks, I'll try that.
redbluegreen