Foros del Web » Programando para Internet » Javascript »

Alguien que controle Javascript y PHP?

Estas en el tema de Alguien que controle Javascript y PHP? en el foro de Javascript en Foros del Web. Alguien que controle PHP y Javascript? Necesito ayuda para enviar una variable a través de javascript en un script de PHP. Adjunto el código para ...
  #1 (permalink)  
Antiguo 12/11/2003, 06:28
Gux
 
Fecha de Ingreso: octubre-2003
Mensajes: 58
Antigüedad: 20 años, 7 meses
Puntos: 0
Exclamación Alguien que controle Javascript y PHP?

Alguien que controle PHP y Javascript?
Necesito ayuda para enviar una variable a través de javascript en un script de PHP. Adjunto el código para ver si alguien tiene la solución. Le he dado mil vueltas pero no consigo enviar la variable de cantidad . Las demás, esto es, tipo, descripcion y precio se envían bien, pero la de cantidad se me resiste. Alguien me puede ayudar? Muchas gracias.


carrito.php
-------------------------------------------------------------------------

<html>
<head>
<title>Carrito de Compra</title>

<link rel="stylesheet" href="estilo.css" type="text/css">
<script LANGUAGE="JavaScript">
<!--
function CargarFoto(img, ancho, alto){
derecha=(screen.width-ancho)/2;
arriba=(screen.height-alto)/2;
string=" toolbar=0,scrollbars=1,location=0,statusbar=0,menu
bar=0,resizable=1,width="+ancho+",height="+alto+", left="+derecha+",top="+arriba+"";
fin=window.open(img,"",string);
}
// -->
</script>
</head>
<body bgcolor="#FFFFFF" link="#32468D" vlink="#800080" class="body">
<SCRIPT LANGUAGE="JavaScript">

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+"]";
}
return true;
}

function resetShoppingBasket() {
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket=.";
}
</SCRIPT>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="640" class="body">
<tr>
<td width="50%"><big><b>Carrito de Compra</b></big></td>
<td width="50%" align="right">[ Carrito de Compra | <a href="estado.php">Estado</a> | <a href="formulario.php">Formulario</a> ]</td>
</tr>
<tr>
<td width="100%" colspan="2">
<hr size="1" color="#000000">
</td>
</tr>
<tr>
<td width="100%" colspan="2"></td>
</tr>
</table>
<table border="1" cellspacing="0" width="640" bgcolor="#E0E0E0" bordercolor="#FFFFFF" class="td">

<tr bgcolor="#7A8EEB" style="color: #FFFFFF; font-family: Verdana, Arial; font-size: 10px;">
<td width="100"> </td>
<td width="290"><b>Producto</b></td>
<td width="90"><b>Precio</b></td>
<td width="120" colspan="2"><b>Cantidad</b></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<form NAME="itemsform">

<?php
include("variableprods.php");
$sql="select * from $table";
$result=mysql_db_query($basedatos,$sql,$link);
while($row=mysql_fetch_array($result))
{
echo("<tr>
<td width='120' valign='top' align='center'><a href=javascript:CargarFoto('imagenes/avestruz.jpg','200','200')><img src='thumbnails/avestruz.jpg' border='0'></a></td>
<td width='340' valign='top'><a href=javascript:CargarFoto('imagenes/avestruz.jpg','200','200')><strong>$row[tipo]</strong></a><br>
<small>$row[descripcion]</small></td>
<td width='60' align='center' valign='top'>$row[precio]</td>
<td width='50' valign='top' align='center'>
<input TYPE='text' NAME='cantidad' VALUE='1' SIZE='3'>
</td>
<td width='70' valign='top'>");?>
<input TYPE='button' NAME='cbtadd' VALUE='Agregar'
onclick="buyItem('<?php echo("$row[tipo]"); ?>','<?php echo("$row[precio]"); ?>', document.itemsform.cantidad.value)">
<?php echo("</td>
</tr>");
}
?>

</form>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="640" class="body">
<tr>
<td width="100%" colspan="2">
<hr size="1" color="#000000">
</td>
</tr>
<tr>
<tr>
<td width="50%"></td>
<td width="50%" align="right">Página [<a href="carrito.php">1</a>]</td>
</tr>
</table>
</center>
</body>
</html>
  #2 (permalink)  
Antiguo 12/11/2003, 07:09
Gux
 
Fecha de Ingreso: octubre-2003
Mensajes: 58
Antigüedad: 20 años, 7 meses
Puntos: 0
ya esta solucionado.
  #3 (permalink)  
Antiguo 12/11/2003, 07:28
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Estupendo

la solución está en http://www.forosdelweb.com/showthrea...hreadid=164873

saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:55.