Jump to content

Anyone know Javascript?


nugenhost

Recommended Posts

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.

Link to comment
Share on other sites

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)"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated