View Full Version : onkeypress?

02-26-2009, 01:24 AM
I have 3 input forms, 1st, 2nd and 3rd number.
I want to display the total after entering the numbers,
please help me.

02-26-2009, 01:35 AM
Please post a link to the page on your site that contains the problematic code so we can check it out.

02-26-2009, 01:42 AM
Not as good as the moderators can do on here, but nonetheless functional, and not using innerhtml. :)....

This Also suppresses "NaN" errors.

parseFloat() is what you are looking for though. It converts strings to values.

<script type="text/javascript">
function addstuff()
function silentErrorHandler() {return true;}
first = parseFloat(document.getElementById('val1').value);
second = parseFloat(document.getElementById('val2').value);
third = parseFloat(document.getElementById('val3').value);
document.getElementById('result').firstChild.nodeValue = first + second + third;
if (document.getElementById('result').firstChild.nodeValue == 'NaN')
{document.getElementById('result').firstChild.nodeValue = "";}
{document.getElementById('result').firstChild.nodeValue = first + second + third;}
One:<input type="text" id="val1" name="val1" onkeyup="addstuff();"><br>
Two:<input type="text" id="val2" name="val2" onkeyup="addstuff();"><br>
Three:<input type="text" id="val3" name="val3" onkeyup="addstuff();"><br>
<a id="result" name="result">&nbsp;</a>