I have 3 input forms, 1st, 2nd and 3rd number.
I want to display the total after entering the numbers,
please help me.
I have 3 input forms, 1st, 2nd and 3rd number.
I want to display the total after entering the numbers,
please help me.
Last edited by kat32; 02-26-2009 at 01:42 AM.
Please post a link to the page on your site that contains the problematic code so we can check it out.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
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.
Code:<script type="text/javascript"> function addstuff() { function silentErrorHandler() {return true;} window.onerror=silentErrorHandler; 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 = "";} else {document.getElementById('result').firstChild.nodeValue = first + second + third;} } </script> 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"> </a>
Last edited by Falkon303; 02-26-2009 at 01:56 AM.
document.write is document.wrong
Bookmarks