problema con variables

titi
13 de Noviembre del 2005
Quiero almacenar los valores de ($_POST[producto] $botones[$_POST[producto]]
en una matriz, pero no se como pues cada vez que pulso un botón se borran todos los datos almacenados anteriormente, y la matriz no avanza, mostrando siempre el elemento actual $nombre matriz [0]. He puesto un ejemplo con javascript lo único que hay que hacer para comprobar lo que digo es pulsar un botón y observar como el contador siempre marca uno en vez de incrementarse como puedo solucionarlo.
Gracias
<html>
<script language="JavaScript">
var numVeces = 0;

function tt()
{
numVeces++;
alert ("Me has pulsado " + numVeces + "veces.");
}
</script>
<?php
$botones = array('a' =>' 100', 'b' =>' 200', 'c' =>' 300','d' =>' 400','e' =>' 500','anular' => null);
foreach ($botones as $producto=>$precio)
echo " <form name='producto' action='Calc.php' method='POST'><input type='submit' value='$producto' name='producto' onClick='tt();'>";
echo "<textarea name='total1' cols='40' rows='20' > ";
if ( $_POST[producto] != anular)
{
?>
&nbsp;
<?php
echo ( $_POST[producto]. $botones[$_POST[producto]]. $_POST[total1]);
}
echo "</textarea ><textarea readonly name='total' cols='10' rows='1' > ";
if ( $_POST[producto] != anular)
{
echo ($botones[$_POST[producto]] + $_POST[total]);
}
echo "</textarea>";
echo "</form>";
?>
</html>

mandm (Loop)
13 de Noviembre del 2005
Titi, esto es un foro PHP................ COMPRENDES???, yo no veo algo que indique Javascript

de cualquier forma ahí tienes esto es lo que necesitas ....

<html>
<head>
<?php
$botones = Array(
"a" => "100",
"b" => "200",
"c" => "300",
"d" => "400",
"e" => "500",
);
$i = 0;
$inputs = "";
echo ("<script type="text/javascript">n");
echo ("costos=new Array();n");
echo ("nombres=new Array();n");
while(list($ind,$mat) = each($botones)){
echo ("costos[".$i."]=".$mat.";n");
echo ("nombres[".$i."]="".$ind."";n");
$inputs.= "<input type="button" value="". $ind ."" onclick="Mysuma('" .$i. "');">&nbsp;&nbsp;n";
$inputs.= "<input type="hidden" id='val".$i."' value='0'>nn";
$i++;
}
echo ("</script>nn</head><body>");
echo ($inputs);
echo ("<input type='button' onclick='resetf();' value='Anular'>");
echo ("<input type='hidden' id='nums' value='".count($botones)."'>n");
?>
<textarea id="cont" readonly></textarea>Total:<input type="text" value="0" id="total" readonly>
<script>
var d = document;
function Mysuma(a){
if(document.getElementById("val" + a)){
value_ = d.getElementById("val" + a).value;
value_++;
alert("Haz hecho click en " + nombres[a] + " " + value_ + " veces.");
d.getElementById("val"+a).value = value_;
d.getElementById("cont").value=d.getElementById("cont").value + nombres[a] + " " + costos[a] + "n";
value_gen = 0;
for(i=0;i<nombres.length;i++){
rp=d.getElementById("val"+i).value;
for(x=0;x<rp;x++){
value_gen+=costos[i];
}
}
d.getElementById("total").value = value_gen;
}
}

function resetf(){
d.getElementById("cont").value = "";
d.getElementById("total").value = 0;
for(i=0;i<nombres.length;i++){
if(d.getElementById("val"+i)){
d.getElementById("val"+i).value = 0;
}
}
}
</script>
<body>
</html>