0
Personal I have the following function:
function validar() {
var campo1 = document.getElementById('subtotal').value;
var campo2 = document.getElementById('totalpagar').value;
if (campo1 != campo2) {
alert('O Total da nota não confere com o Total a ser pago');
return false; //Parar a execucao
}
}
And the following inputs:
<div align="center">
<label for="subtotal">Total Nota R$: </label>
<input type="text" name="subtotal" id="subtotal" size="8" />
</div>
<div align="center">
<label for="totalpagar">Total Pgto R$: </label>
<input type="text" name="totalpagar" id="totalpagar" size="8" />
</div>
These inputs come from other functions.
I needed to compare these two, issue the alert and not allow you to record the information when you click send and not ask what is already typed.
I tried to use the onsubmit
but it didn’t work out.
What do you mean "comes from other functions"? Apparently the code works: look at this Jsfiddle with your code. The only difference is the button I placed so you could test the function.
– José