Welcome to WebmasterWorld Guest from 54.167.209.198

Forum Moderators: open

Message Too Old, No Replies

javascript math

15 + 15=1515?

     
8:52 pm on May 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Hello. I'm trying to add two variables(numbers), but instead of totaling the numbers, they go back to back.

function buy()
{
var mat=document.veilopts.illusion.value;
var length1=document.veilopts.tier1.value;
var length2=document.veilopts.tier2.value;
var length3=document.veilopts.tier3.value;
var trim=document.veilopts.edge.value;
var motif=document.veilopts.fill.value;
var calcveil1=length1 + length2 + length3
var sOrder = "https://www.paypal.com/cart/add=1&business=m00n106%40aol.com&item_name=Veil w/"+mat+"bridal illusion and "+trim+" edge. Tier 1 is "+length1+" long. Tier 2 is "+length2+" long. Tier 3 is "+length3+" long. Illusion motif selected:"+motif+"&item_number=&amount="+ calcveil1;
alert(sOrder);
window.open(sOrder,'cartwin','width=600,height=400,scrollbars,location,resizable,status');
}

8:55 pm on May 3, 2002 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


I am sure that someone has a better answer than this but I have had to multiply the var before to convince them that they are numeric values.

var calcveil1=(length1 * 1) + (length2 * 1) + (length3 *1)

as I said there is probably something better but this works well.

(edited by: jatar_k at 8:56 pm (utc) on May 3, 2002)

8:55 pm on May 3, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Nov 5, 2001
posts:232
votes: 0


Javascript thinks that you are putting two strings back to back. You need to define them as intengers
9:17 pm on May 3, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Nov 5, 2001
posts:232
votes: 0


Try using the Math object.

someVar = Math.TotalLength(Length1+Length2);

9:22 pm on May 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Thank you jatar_k and pcguru333! I'm good to go, at least for now.
Peace:)
9:22 pm on May 3, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Nov 5, 2001
posts:232
votes: 0


If you need to convert a number to a string use

Var LengthString = SomeNumberVar.toString();

9:23 pm on May 3, 2002 (gmt 0)

Full Member

10+ Year Member

joined:Feb 28, 2001
posts:208
votes: 0


You can also do this:

var length1 = parseFloat(document.veilopts.tier1.value);
var length2 = parseFloat(document.veilopts.tier2.value);
etc...

10:27 pm on May 3, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 4, 2001
posts:997
votes: 0


To convert a number to string in j/s, its easier to use somenum = somenum + '';
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members