deleting items from list


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: deleting items from list

Hybrid View

  1. #1
    KenD Guest

    deleting items from list


    I am displaying a list of items dynamically retrieved from an SQL database.
    I've put a 'delete' button on each line item, which calls a stored procedure
    to delete that item from the database.

    The trouble is this: When I hit a delete button, the browser goes blank,
    and I have to hit the browser Back button, then Refresh in order to see the
    revised list.

    Is there a way to do this so the item is deleted, and the page refreshes
    automatically?

  2. #2
    Russell Jones Guest

    Re: deleting items from list

    Here are two ways to do this.

    The best method would be to use remote scripting (or in IE, the
    XMLHTTPRequest object) to call the server to delete the item, and then just
    remove the deleted item from the existing list control using client-side
    script. Note that you need to be able to check a return value from the
    server to ensure that the item was actually deleted, or that it no longer
    exists (because someone else deleted it already). Because you're working in
    a multi-user situation, you might be better off having the server return the
    complete list, which would then reflect the current state of the "real" list
    on the server (e.g. someone else might have deleted an item since the last
    time the current user displayed the list).

    Alternatively, you can have the page that calls the stored procedure return
    the same page that the user is looking at--with the new data. The
    disadvantage of this method is that the browser will refresh the entire page
    rather than just the list data. The advantage is that it's easier to create.

    If you decide to refresh only the list rather than the entire page, and your
    items are in a select list, use the options collection to remove items from
    the list. If your items consist of a list of text and links, you can use the
    following example to get started.

    <html><head><title>List Delete Example</title></head><body>
    <span name="e1" id="e1"><a

    href="JavaScript:deleteItem('e1');">del</a>&nbsp;Item 1<br></span>
    <span id="e2"><a href="JavaScript:deleteItem('e2');">del</a>&nbsp;Item

    2<br></span>
    <span id="e3"><a href="JavaScript:deleteItem('e3');">del</a>&nbsp;Item

    3<br></span>
    <span id="e4"><a href="JavaScript:deleteItem('e4');">del</a>&nbsp;Item

    4<br></span>
    <span id="e5"><a href="JavaScript:deleteItem('e5');">del</a>&nbsp;Item

    5<br></span>
    </body></html>
    <script type="text/JavaScript">
    function deleteItem(id) {
    // call the URL to delete the list item here
    // check the return value. If successful,
    // hide the item by setting its style.display attribute to "none"
    el = document.getElementById(id);
    if (el != null) {
    el.style.display="none";
    }
    }
    </script>

    "KenD" <devx@kendietz.com> wrote in message
    news:3dc858a8$1@tnews.web.devx.com...
    >
    > I am displaying a list of items dynamically retrieved from an SQL

    database.
    > I've put a 'delete' button on each line item, which calls a stored

    procedure
    > to delete that item from the database.
    >
    > The trouble is this: When I hit a delete button, the browser goes blank,
    > and I have to hit the browser Back button, then Refresh in order to see

    the
    > revised list.
    >
    > Is there a way to do this so the item is deleted, and the page refreshes
    > automatically?




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center