Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

math question 2

Status
Not open for further replies.

codeone

Programmer
Mar 25, 2003
343
US
hey,
got a simp[le math question, I need to add to values from two different texboxes and I tried like so:

Code:
function sumIt(){
var te = document.alpha.a6.value;
var et = document.alpha.a7.value;
var fin = te + et;
document.alpha.l0.value='$'+fin;
}

but it jus concentates it and doesnt add the two values together. How can I make this add the two values?

thanks

co

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
Code:
function sumIt(){
   var te = document.alpha.a6.value * 1;
   var et = document.alpha.a7.value * 1;
   var fin = te + et;
   document.alpha.l0.value='$'+fin;
}
 
sweet!! Thanks alot!!!

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
Functionality wise, the above example would yield the correct results (as would subtracting the numbers by 0, or dividing them by 1). However, programmatically it is correct to use parseInt or parseFloat depending on what type of numbers you're dealing with. Looks like you're dealing with currency so parseFloat is probably what you want:
Code:
function sumIt(){
   var te = parseFloat(document.alpha.a6.value);
   var et = parseFloat(document.alpha.a7.value);
   var fin = te + et;
   document.alpha.l0.value='$'+fin;
}



-kaht

banghead.gif
 
a star to kaht for suggesting use of the proper methods vs. hacks

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
tis nothing wrong with hacks...thanks kaht for the example code, I like either or, as long as it works, it's fine with me...

regards

co

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
daily mail?...like the uk version of the american tabloids?

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
Ok, we will hence forward translate all things not American for you guys! :-D

Queen: like American president but (slightly) prettier.

 
true she is prettier except we got to choose who ruins our country...lol

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
well for us both...lol, jk

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top