nugenhost Posted August 18, 2008 Share Posted August 18, 2008 I'm in need of a bit of help on a javascript form. I know a bit but I'm having an issue with getting what I need done, done correctly. A bit of info. What I have is a financial form. I have 2 columns that need to be each added up then the total of those two columns need to be totaled together later in the form. I can get the one side to calculate out and total but I can't get the second side to calculate out correctly. The other issue I'm having with it is unless I put a .15 (cents) value after a dollar amount it's not giving me .00 after the dollar amount. I'm at a loss on how to fix that as well. function b_startCalc(){ interval = setInterval("calc()",1); } function calc(){ v1 = document.autoForm.b_firstjob.value; v2 = document.autoForm.b_oth_income.value; document.autoForm.b_total_income.value = (v1 * 1) + (v2 * 1); } function b_stopCalc(){ clearInterval(interval); } As you can see it's just a basic add script, but I'm at a loss. If anyone can help me I'd very much appreciate it. Thanks. 0 Quote Link to comment Share on other sites More sharing options...
ur Posted August 19, 2008 Share Posted August 19, 2008 I don't know what you mean by not getting "one side to calculate out", but for the number formatting you can use the number.toFixed(x) javascript function (it will round naturally). replace: document.autoForm.b_total_income.value = (v1 * 1) + (v2 * 1); with: var total; total = v1+ v2; document.autoForm.b_total_income.value = total.toFixed(2); edit... If you have losts of visitors with older browsers or js, you should first test if the function exists with "if (total.toFixed)" 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.