Hi, I am making a favorite list where you can add items through javascript and remove them again. The values are stored in cookies to remember the list when the user returns. The problem I have is that the method to remove the items from the list doesn't get run, unless there has been a postback first. My code to remove items look like this:
function removeFavorite(OrderId) {
debugger;
var cookieValues = jQuery.cookie('FavoriteList');
var cookieArray = cookieValues.split(",");
for (var i = 0; i < cookieArray.length; i++) {
if (cookieArray[i] == OrderId) {
cookieArray.splice(i, 1);
}
}
jQuery('li#liFavoriteOrder_' + OrderId).remove();
jQuery.cookie('FavoriteList', cookieArray.join(","));
}
and the code to call the method looks like this:
<a onclientclick="removeFavorite(1272331)" style="cursor: pointer;">
and the list looks like
<ul id="ulFavoriteList">
<li id="FavoriteId_1272331">
Milk
<a onclientclick="removeFavorite(1272331)" style="cursor: pointer;">
<img src="/Images/Icons/bullet_toggle_minus.png"/>
</a>
</li>
</ul>
The code to add to to the list looks a bit like this (short version):
jQuery('<li id=\"liFavorite_' + OrderId + '\"><a target=\"_blank\" href=\"' + url + '\">' + OrderName + '</a><a style="cursor:pointer;" onclientclick="removeFavorite(' + OrderId+ ')"><img src="/Images/Icons/bullet_toggle_minus.png" /></a></li>').appendTo('ul#ulFavoriteList');