Re: Variables - Integer vs. Character

by "Frank Boumphrey" <bckman(at)ix.netcom.com>

 Date:  Mon, 12 Feb 2001 00:27:37 -0500
 To:  <hwg-techniques(at)hwg.org>,
"Nathan Lyle" <natlyle(at)nmu.edu>
 References:  nmu
  todo: View Thread, Original
The easieast way is to subtract 0

var i=1
var i=2
var x=1+2

to make sure you get 3 and not twelve

put var x=1+2-0

HTH

Frank

----- Original Message -----
From: "Nathan Lyle" <natlyle(at)nmu.edu>
To: <hwg-techniques(at)hwg.org>
Sent: Sunday, February 11, 2001 10:21 PM
Subject: Variables - Integer vs. Character


> Okay, this has been a thorn in my side for a long time, but I've
always
> managed to come up with some kludge that kept me from having to
actually
> find the answer. Until now. <sigh> How do I stop Javascript from
treating
> an int like a character? I have the following code:
>
> totalCost = base;
> totalCost += document.forms[0].motherboard_cost.value;
> totalCost += document.forms[0].hard_drive_cost.value;
> totalCost += document.forms[0].windows_software_cost.value;
> totalCost += document.forms[0].monitor_speakers_cost.value;
> totalCost += document.forms[0].sdram_cost.value;
> totalCost += document.forms[0].software_suite_cost.value;
> document.forms[0].total.value = totalCost;
>
> Instead of adding values, I get concatinated results. (10 + 10 =
1010
> instead of 20.)
>
> Any ideas? Please please please?
>
> ~Nathan Lyle   (The Tragic Comedian Poet)
>
> Email:  natlyle(at)nmu.edu    or    jopling(at)geocities.com
> Web: http://euclid.nmu.edu/~natlyle
> Phone: 906-227-5736
>
> "Where would Christianity be if Jesus got eight to fifteen years
with time
> off for good behavior?" - New York State Senator James Donovan,
speaking in
> support of capital punishment. Quoted in the liner notes of an album
by
> Jello Biafra & Mojo Nixon
>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA