Código PHP:
function restar() {
var monto = <?php echo $_POST['monto']; ?>;
var inputs = document.getElementsByTagName('input');
var total = document.getElementById('totales');
for (var i=0; i<inputs.length; i++) {
if (inputs[i].id.substring(0,5) == 'valor') {
monto -= Number(inputs[i].value);
}
}
total.value = monto;
}
function validarMonto() {
var monto = document.getElementById('totales').value;
var montoInicial = <?php echo $_POST['monto']; ?>;
if (monto == montoInicial) {
alert('debe ingresar al menos un numero para realizar la resta');
}else{
alert('la resta se realizo correctamente');
}
}
window.onload = function() {
restar();
var inputs = document.getElementsByTagName('input');
for (var i=0; i<inputs.length; i++) {
inputs[i].onkeyup = restar;
}
document.getElementById('siguiente').onclick = validarMonto;
}
Código HTML:
Valor 1 <input type="text" id="valor0"/><br><br>
Valor 2 <input type="text" id="valor1"/><br><br>
Valor 3 <input type="text" id="valor2"/><br><br>
Totales <input type="text" id="totales" value="Resta"/>
<input type="button" id="siguiente" value="siguiente" />
aca esta le cambie algunas cosas y funciona lo unico que tenes que hacer ahora es un formulario en la pagina previa que pase la variable yo use un formulario asi...
Código HTML:
<form action="productos.php" method="post">
<input type="text" name="monto" />
<input type="submit" value="enviar" />
</form>
salu2