Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/09/2007, 00:23
Avatar de insyse
insyse
 
Fecha de Ingreso: abril-2005
Ubicación: Colombia
Mensajes: 206
Antigüedad: 19 años
Puntos: 5
Variable PHP en Javascript (Error de sintaxis)

Hola a todos...

Estoy haciendo un carrito de pedidos en linea, inicialmente trabaja con Javascript correctamente, con variables definidas...

El problema nace cuando mi cliente quiere que le haga un administrador en pHP para modificar esta variables (Item, Valor), pero al tratar de insertar el código PHP en el script me da error de sintaxis, después de verificar bien observo que el problema esta en las comillas, ya he tratado todos los métodos que conozco y no logro hacer que fucnione... espero que alguien me pueda ayudar.

Anexo el código base de PRODUCTO.PHP, como lo uso sin variables PHP, si alguien sabe como puedo incrustar las variables en el Javascritp, le agradezco me corrija el codigo.



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento</title>
</head>
<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>


<tr>
<td valign="top">


<p>EN LA SIGUIENTE LINEA ESTA EL VALKOR QUE DEBO CONVERTIR EN VARIABLE DE PHP (Ping Pong - 9421)</p>
<input type="submit" name="Submit2" value="Agregar" onclick="buyItem('Ping Pong - 9421','0', 1)"/> </td>
</tr>
</body>
</html>




Gracias.