Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/12/2003, 13:31
Pasky
 
Fecha de Ingreso: julio-2003
Mensajes: 124
Antigüedad: 20 años, 9 meses
Puntos: 0
E-commerce con Javascript

Hola a todos y a ver si me podéis echar una mano.

Estoy un poco verde en estos temas, pero espero eplicarme lo mejor posible.

Tengo un problema con una cookie que no actua en toda la página. En cuanto cambio de directorio la cookie digamos que se borra.

Creo que el problema lo tengo en alguna parte de este código:

index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
function alterError(value) {
if (value<=0.99) {
newPounds = '0';
} else {
newPounds = parseInt(value);
}
newPence = parseInt((value+.0008 - newPounds)* 100);
if (eval(newPence) <= 9) newPence='0'+newPence;
newString = newPounds + '.' + newPence;
return (newString);
}
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
totprice = totprice + itemtotal;
itemlist=itemlist+1;
} else if (fulllist.substring(i,i+1) == ',') {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}

function buyItem(newItem, newPrice, newQuantity) {
if (newQuantity <= 0) {
rc = alert('La cantidad ingresada es incorrecta');
return false;
}
if (confirm('¿Agregar '+newQuantity+' '+newItem+' al carrito?')) {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
document.cookie="TheBasket="+document.cookie.subst ring(countbegin, countend)+"["+newItem+","+newPrice+"#"+newQuantity+"]";
window.location.reload();
}
return true;
}

function resetShoppingBasket() {
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket=";
}

Igual es alguna tonteria, pero no lo sé.

Muchas gracias y saludos.