Results 1 to 6 of 6

Thread: clear shopping cart content on body unload

  1. #1
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default clear shopping cart content on body unload

    hi all

    i m creating a shopping cart in php.

    i want to add a javascript function on body unload that when the user closes his browser then he will get an confirm alert that the shopping cart contents should get clear or remove,
    if he clicks ok then the contents should get removed and if clicks cancel then nothing happens.

    how is it possible with javascript. my shopping cart contents are inside the <form> tag.

    vineet

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Code:
    <script type="text/javascript">
    window.onbeforeunload = function() {
       return 'Are you sure you want to leave the page?';
    };
    </script>
    Jeremy | jfein.net

  3. #3
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default clear cart on body unload

    Quote Originally Posted by Nile View Post
    Code:
    <script type="text/javascript">
    window.onbeforeunload = function() {
       return 'Are you sure you want to leave the page?';
    };
    </script>
    hi nile

    thanks for reply. this script gives a confirm alert but it gives alert on every refresh command also. that should not be there.

    but on clicking the ok button i want to clear the contents. This script doesnt do that.

    do i need to clear contents with php

    vineet
    Last edited by vineet; 11-04-2008 at 04:25 AM. Reason: SOMETHING MISS

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Are you making it with PHP? Probably, right? So PHP, your gonna need to use ajax.
    Jeremy | jfein.net

  5. #5
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default clear shopping cart

    Quote Originally Posted by Nile View Post
    Are you making it with PHP? Probably, right? So PHP, your gonna need to use ajax.
    hi nile

    thanks for the reply.
    at present i have no knowledge about ajax. But if its possible with ajax then i will search for it as i even dont know how to implement in php.

    vineet

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, if you need any help, just post!
    This become of some help too:
    http://www.dynamicdrive.com/dynamici...jaxroutine.htm
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •