PDA

View Full Version : clear shopping cart content on body unload



vineet
11-04-2008, 03:51 AM
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

Nile
11-04-2008, 04:10 AM
<script type="text/javascript">
window.onbeforeunload = function() {
return 'Are you sure you want to leave the page?';
};
</script>

vineet
11-04-2008, 04:18 AM
<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

Nile
11-05-2008, 12:40 PM
Are you making it with PHP? Probably, right? So PHP, your gonna need to use ajax.

vineet
11-05-2008, 02:56 PM
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

Nile
11-06-2008, 12:28 PM
Ok, if you need any help, just post!
This become of some help too:
http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm