Re: Variables - Integer vs. Character

by =?iso-8859-1?Q?Josu=E9_Figueira_Machado?= <jmachado(at)mindspring.com>

 Date:  Mon, 12 Feb 2001 08:24:13 -0500
 To:  <hwg-techniques(at)hwg.org>,
"Nathan Lyle" <natlyle(at)nmu.edu>
 References:  nmu
  todo: View Thread, Original
Why don't you use parseInt()? There you go:

totalCost = base;
totalCost += parseInt(document.forms[0].motherboard_cost.value);
totalCost += parseInt(document.forms[0].hard_drive_cost.value);
totalCost += parseInt(document.forms[0].windows_software_cost.value);
totalCost += parseInt(document.forms[0].monitor_speakers_cost.value);
totalCost += parseInt(document.forms[0].sdram_cost.value);
totalCost += parseInt(document.forms[0].software_suite_cost.value);
document.forms[0].total.value = totalCost;

HTH,

Josu�

----- 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?

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