Código :
<html> <head> <script language="javascript"> function sumar() { var a, total = 0; var elements = document.getElementsById('sumar'); for(a=0; a<elements.length; a++){ total += (parseFloat(elements[a].value)); } document.getElementById("resultado").value = total; } </script> <title>suma y suma</title> </head> <body> <?php $v = 1; if(isset($_POST["ok"])) { $numero = $_POST["valor"]; $numero++; $v = $numero; } ?> <form method="post" action="#"> <?php for($a=0;$a<$v;$a++) { ?> <input type="text" name="<?php echo "sumar$a"; ?>" <?php if(isset($_POST["ok"])) echo "value='" . $_POST["sumar$a"] . "'"; ?> id='sumar' onKeyUp="sumar()" size="8" />+ <?php } ?> // <input type="hidden" name="valor" value="<?php echo $a; ?>" /> <input type="submit" name="ok" value="otro input"/>= <input type="text" name="total" id="resultado" readonly="readonly" /> </form> </body>
</html>