2
I’m trying to create a script on javascript to take a value entered by the user, and multiply by the specified value, but whenever I click the button, it performs the calculations, but, it updates the page then zeroing.
Follow code I used:
document.getElementById("btn").onclick = function() {
var valorProduto = "";
valorProduto = document.getElementById("vp").value * 2;
document.getElementById("valorST").innerHTML = valorProduto;
}
<p>Valor do produto:
<input type="text" id="vp">
</p>
<p id="valorST">valor</p>
<button id="btn">Calcular</button>
Puts a
return false;after the last line of the script.– Diego Souza
possibly your
buttonmay be inside aform, depending on how you have implemented this may give arefreshon the page if theactionis empty if theactionis completed, it will redirect, thereturn false;as told by @zooboomafoo can prevent this :)– MarceloBoni
Just one more thing, this has nothing to do with loop rs
– MarceloBoni
I understood Marcelo, I really expressed myself wrong at first, rs
– Rick Parapinski