Welcome to WebmasterWorld Guest from 54.161.181.156

Forum Moderators: open

javascript math

15 + 15=1515?

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

WebmasterWorld Senior Member 10+ Year Member



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)

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



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)

10+ Year Member



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)

10+ Year Member



Try using the Math object.

someVar = Math.TotalLength(Length1+Length2);

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

WebmasterWorld Senior Member 10+ Year Member



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)

10+ Year Member



If you need to convert a number to a string use

Var LengthString = SomeNumberVar.toString();

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

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month