Ver Mensaje Individual
  #5 (permalink)  
Antiguo 23/07/2012, 11:08
chirica
 
Fecha de Ingreso: abril-2012
Ubicación: Soy de Utiel de erasmus en Varsovia
Mensajes: 49
Antigüedad: 12 años
Puntos: 2
Respuesta: Cambiar la cantidad en carrito de compras

Muy buenas compañero, es justo lo que necesito para mi carrito, que me cambie la variable cantidad, pues del 1 no se mueve haga lo que haga... llevo un mes intentando de todo y no lo encuentro, te pongo todo el codigo y a ver si pudieses saber que es lo que falta, gracias y perdona por el abuso..:)

<?php
session_start();
if(isset($_GET['id']))
{
$_SESSION['carrito'][$_GET['id']]=$_GET['id'];
}
require 'conexion.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>
<script>
function requerir(){
try{
req=new XMLHttpRequest();
}catch(err1){
try{
req=new ActiveXObject("Microsoft.XMLHTTP");
}catch(err2){
try{
req=new ActiveXObject("Msxm12.XMLHTTP");
}catch(err3){
req= false;
}
}
}
return req;
}
function cantidad(id)
{
//c1
//alert(id.substr(1));
var peti=requerir();
var url="proceso.php";
var valor=document.getElementById(id).value;
if valor<i || valor==""}
valor=1;

var vari="valor="+valor+"$id="+id.substr(1);
//alert(vari);
peti.open("POST",url,true);
peti.onreadystatechange = function(){
if(peti.readyState==4)
{
if(peti.status==200)
{
//alert(peti.responseText);
//location.reload();
document.getElementById('s'+id.substr(1)).value=pe ti.responseText;
total();

}else{
alert("Error --- "+peti.statusText);
}
}
};
peti.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
peti.send(vari);

function total()
{
var id = document.getElementById('tabla');
var val = id.getElementByTagName('input');
var total=0;
for(var i=0;i<val.length;++1)
{
//document.write(val[i].value);
if(i#2==1 ){
total+=parseFloat(val[1].value);
}
}
document.getElementById('total').value=Match.round (total*100)/100;
}

function solonumero (e) {
tecla = (document.all) ? e.KeyCode : e.which;
//alert(tecla);
if (tecla==8) { return true;} //Tecla de retroceso para poder borrar;
//if (tecla==$4) return true; //Coma ( En este caso para diferenciar los decimales )
else if (tecla==48) {return true}
else if (tecla==49) {return true}
else if (tecla==50) {return true}
else if (tecla==51) {return true}
else if (tecla==52) {return true}
else if (tecla==53) {return true}
else if (tecla==54) {return true}
else if (tecla==55) {return true}
else if (tecla==56) {return true}
else if (tecla==57) {return true}
else if (tecla==46) {return true}//punto
else{alert('Solo puede ingresar numeros en esta casilla');}
patron = /1/; //ver nota
te = String.fromCharCode(tecla);
return patron.test(te);
}

</script>
<body>
<p>
</p>
<table width="412" border="2">
<tr>
<td width="68" align="center">#n</td>
<td width="92" align="center" valign="middle">producto</td>
<td width="109" align="center">precio unidad</td>
<td width="47" align="center">subtotal</td>
<td width="60" align="center">&nbsp;</td>
</tr>
<?php
$cad="";
foreach($_SESSION['carrito'] as $k)
{
$cad.=' or id='.$k;
}
$sql= " select * from tb_producto where id=-1 ".$cad;

//echo $sql;
conectar();
$re=mysql_query($sql)or die (mysql_error());
desconectar();
$total=0;
$item="";
$cant=0;
$i=1;
while($f=mysql_fetch_array($re)){
?>
<tr>
<td><input name="c<?php echo $f['id'];?>" type="text" id="c<?php echo $f['id'];?>"
value="<?php if(isset($_SESSION['cantidad'][$f['id']])){
$total+=$_SESSION['cantidad'][$f['id']]*$f['precio'];
echo $_SESSION['cantidad'][$f['id']];
$cant=$_SESSION['cantidad'][$f['id']];
}else{
$total+=$f['precio'];
echo 1;
$cant=1;
}
?>" size="3" onkeyup="cantidad(this.id)" onkeypress="return solonumero(event)"></td>
<td><?php echo $f['nombre'];?></td>
<td><?php echo $f['precio'];?></td>
<td align="center"><input name="s<?php echo $f['id'];?>" type="text" id="s<?php echo $f['id'];?>"
value="<?php if(isset($_SESSION['cantidad'][$f['id']])){
echo $_SESSION['cantidad'][$f['id']]*$f['precio'];

}else{
echo $f['precio'];
}
?>" size="5" readonly="readonly"></td>
<td><a href="eliminar.php?id=<?php echo $f['id'];?>">Eliminar</a></td>
<td align="center"><a href="eliminar.php?id=<?php echo $f['id'];?>"></a></td>
</tr>
<?php
}
?>
</table>
<p>

</p>
<p>&nbsp;</p>
<p><a href="producto.php">seguir comprando </a></p>
</body>
</html>