Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function cambiarTalle()
{
document.itemsform.text3.value =
document.itemsform.newTalle.options [document.itemsform.newTalle.selectedIndex].value;
document.itemsform.text2.value =
document.itemsform.newTalle.options[document.itemsform.newTalle.selectedIndex].text;
}
</script>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
function buyItem(newItem, newPrice, newQuantity, newTalle) {
if (newQuantity <= 0) {
rc = alert('La cantidad ingresada es incorrecta');
return false;
}
if (confirm('¿Agregar '+newQuantity+' '+newItem+' '+newTalle+' 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.substring(countbegin, countend)+"["+newItem+","+newTalle+","+newPrice+"#"+newQuantity+"]";
}
return true;
}
function resetShoppingBasket() {
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket=.";
}
</SCRIPT>
<form NAME="itemsform">
art352
<input name="producto" type="hidden" id="producto" value="art352">
<input TYPE="value" NAME="agregar1" VALUE="1"SIZE="3">
<input type="text" name="text3" style="border:0;">
<input type="text" name="text2" style="border:0;">
<select size="1" name="newTalle" ONCHANGE="cambiarTalle()">
<option value="0">Talle...</option>
<option value="30">T8</option>
<option value="31">T10</option>
<option value="32">T12</option>
</select><br>
<input type="button" name="cbtadd" value="Agregar" onClick="buyItem(document.itemsform.producto.value,
document.itemsform.newTalle.value,
document.itemsform.agregar1.value,
document.itemsform.text2.value)">
</body>
</html>
Código HTML:
<html>
<title>Estado del Carrito</title>
<SCRIPT LANGUAGE="JavaScript">
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);
}
function showItems() {
var theitem="";
var thetalle="";
var thequantity="";
var theprice="";
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('<form><table border="1" cellspacing="0" width="640" bgcolor="#E0E0E0" bordercolor="#FFFFFF" class="td">');
document.writeln('<TR><TD width="150"><b>Producto</b></TD><TD width="50"><b>Talle</b></TD><TD width="80" align="right"><b>Cantidad</b></TD><TD width="120" align="right"><b>Costo x unidad</b></TD><td width="100" align="right"><b>Costo total</b><TD width="90"> </TD></TR>');
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;
var tax = itemtotal / 100 * (0 - 0);
tax = Math.floor(tax * 100)/100
totprice = totprice + itemtotal + tax;
itemlist=itemlist+1;
document.writeln('<tr><td>'+theitem+'</td><td align=right>'+thetalle+'</td><td align=right>'+thequantity+'</td><td align=right>'+theprice+'</td><td align=right>'+alterError(itemtotal)+'</td><td align=center><input TYPE="button" NAME="remove" VALUE="Quitar" onclick="javascript:removeItem('+itemlist+')"></td></tr>');
theitem="";
thetalle="";
} else if (fulllist.substring(i,i+1) == ',' && theitem=="" && thetalle=="") {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ',' && thetalle=="") {
thetalle = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}
document.writeln('<tr><td colspan=4><b>Total</b></td><td align=right>'+alterError(totprice)+'</td><td> </td></tr>');
document.writeln('</TABLE>');
}
function removeItem(itemno) {
newItemList = null;
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;
theitem = fulllist.substring(itemstart, itemend);
itemlist=itemlist+1;
if (itemlist != itemno) {
newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
}
}
}
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket="+newItemList;
top.location = "estado.htm";
}
function clearBasket() {
if (confirm('¿Confirma que desea reestablecer el carrito?')) {
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket=.";
top.location = "estado.htm";
}
}
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
showItems();
</SCRIPT>
</html>
A ver si descubres que he cambiado....
Un consejo llama a las cosas por su nombre y no hagas cosas como esta....
buyItem(newItem, newPrice, newQuantity, newTalle)
buyItem("art352",document.itemsform.newTalle.value ,document.itemsform.agregar1.value,document.itemsf orm.text2.value)
newItem="art352" OK
newPrice=document.itemsform.newTalle.value
!!!
newQuantity=document.itemsform.agregar1.value
!!!
newTalle=document.itemsform.text2.value
!!!
el precio en el value del talle??
Quim