mailmeakhila has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, I need your expertise to help resolve this problem. I am building an online shopping cart. After the user has selected many items. i am building a table with all the items in his virtual cart(i have added all the cart items to the cookie). Now i want to give the user an option to delete items. I have a template page and my perl script to pass values to the template page. I could get the values to be deleted from the table but not able to update the cookie with the deleted items.I have tried to use <script> tag inside another javascript but it didnt work.
<script type="text/javascript"> function removeRow(src) { var oRow = src.parentNode.parentNode; document.getElementById("cart").deleteRow(oRow.rowInde +x); var title = oRow.cells[0].innerHTML; document.write("<scr"+"ipt language='javascript' src=' +http://localhost/sellaphone/temp.pl?title'></sc"+"ript>"); } </script>
Below is part of my perl script:
if ($title) { push @{$cart}, {TITLE=>$title,ANS1=>$a +ns1,ANS2=>$ans2,ANS3=>$ans3,ANS4=>$temp}; $session->param("CART",$cart); } my $template = HTML::Template->new(filename => +'checkouttemp.html'); $template->param(ROWS=>$cart); print $template->output(); }
Any help is really appreciated. Thank you Akhila.

Replies are listed 'Best First'.
Re: Javascript to edit cookie set by perl
by Corion (Patriarch) on May 22, 2012 at 17:37 UTC

    You don't show us at all how your cookie is constructed, so how do you think we can help you?.

    My advice is to store the cart items in the session on the server side, and not in the client cookie. From Javascript, just reload the part of the cart page after removing an item.

    Upon looking further at the fragments of your code, it seems you never store the items on the client but only store the items in the session already. So from your Javascript, you will need to send a request to your Perl code to remove an item. I recommend doing that without Javascript first and later add something like the jQuery .load() function to reload parts of an HTML page.