javascript - Automatic percentage calculator -
i working on code calculate percentage need calculate percentage automatically without submit button, want output calculated percentage without need of user hitting submit button.
here code
input: <input type="text" id="input"/><br /> percent: <input type="text" id="percent" value="50"/>%<br /> output: <input type="text" id="output"/> function calc() { var = document.getelementbyid("input").value; var p = document.getelementbyid("percent").value; var o = (i/100) * p; document.getelementbyid("output").value = o; }
on each of 2 inputs, add onchange="calc();"
(updates when user tabs next field) or onkeyup="calc();"
(updates whenever user types something).
Comments
Post a Comment