estoy haciendo una orden de pedido para una empresa de remeras en javascript y tengo el sig problemita..agradeceria mucho que me puedan ayudar ya que soy muy limitado en programacion.. al grano..
la pagina carrito.htm consta de un formulario en donde para hacer un pedido se necestia poner la cantidad y q talle de remera el cliente va a pedir y apretando el boton Agregar manda todos los datos a estado.htm...
en estado.htm se puede ver el detalle de lo que el cliente agrego y aparece lo sig
Producto/Cantidad /Costo x unidad /Costo total ..
yo necesitaria agregar un ITEM TALLE
creo q el error esta en la funcion "buyItem" del archivo carrito.htm yo intente con agregarle newTalle y no me funciono
intente de mil formas y no tube suerte ..bueno espero que me puedan ayudar ..desde ya mil gracias
carrito.htm
<html>
<head>
<script language="JavaScript">
Código:
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 >
Código:
<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>
Código:
<form NAME="itemsform">
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></td>
<td width="70" valign="top"><input type="button" name="cbtadd" value="Agregar"onClick="buyItem('art352',document.itemsform.newTalle.value,document.itemsform.agregar1.value,document.itemsform.text2.value)">
</td>
</body>
</html>
estado.htm
Código:
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() {
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>'+theitem+'</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>');
} 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;
}
}
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>