Wedcikebreene
New Member
I have found a lot of answers to this question but I have no idea which is the best answer or where to add it..This is the code:\[code\] // CSS // <html> <head> <script type="text/javascript" language="Javascript"> var v1 = 0; var v2 = 0; var answer = 0; function calculate () { answer = v1 / v2; var elem; elem = document.getElementById("v1"); elem.value = http://stackoverflow.com/questions/13734139/v1; elem = document.getElementById("v2"); elem.value = http://stackoverflow.com/questions/13734139/v2; elem = document.getElementById("answer"); elem.value = http://stackoverflow.com/questions/13734139/answer; } function setValue(elem) { var val = 0.0; if (elem.value !="") { val = parseFloat(elem.value); } else { val = 0.0; } switch (elem.id) { case "v1": v1 = val; break; case "v2": v2 = val; break; } calculate(); } </script> [..] </head> [...]\[/code\]and\[code\] // HTML //[...]<form><input type="text" id="v1" onKeyUp="javascript: setValue(this);"><input type="text" id="v2" onKeyUp="javascript: setValue(this);"><input type="text" id="answer" readonly></form>[...]\[/code\]Now, what would make the result show or print (I don`t know which one is correct) only 2 decimals and where should that be placed?Thanks.