Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding

Reply
 
LinkBack Thread Tools
Old 06-08-08   #1 (permalink)
First Time Build
 
intel ati

Join Date: Dec 2007
Location: Australia
Posts: 827

Rep: 56 wolf_08 is acknowledged by some
Unique Rep: 45
Trader Rating: 0
Default Javascript help

So I am doing a simple menu ordering for a javascript class but the only problem I have is that I need to add up three text fields which when you on click on a item it will have the cost (in one of the text fields) which contain decimals in them. I tryed parseFloat() and parseInt() but it doesn't work with decimals.

Is their a way to add numbers that have decimals in them?
__________________
System: Xero
CPU
Q6600
Motherboard
GA-EX38-DS4
Memory
2 * 1 DDR2 800 Kingston
Graphics Card
Gecube 3870 O/C edition
Hard Drive
1 Maxtor ATA 200gigs, 1 Samsung SATA-2 500gigs
Sound Card
Integrated sound
Power Supply
OCZ 600watts
Case
Icute with side window and 25cm side fan
OS
Vista Home Premium
Monitor
View Sonic 17"
wolf_08 is offline   Reply With Quote
Old 06-09-08   #2 (permalink)
Programmer
 
stupid's Avatar
 
amd nvidia

Join Date: Jan 2006
Location: Fahaheel, Kuwait
Posts: 1,224

Rep: 144 stupid is acknowledged by manystupid is acknowledged by many
Unique Rep: 113
FAQs Submitted: 1
Trader Rating: 4
Default

You just have to convert them to decimals (doubles) right away.

Here is a full example
Code:
<head>
    <title>JS Example</title>
    <script type="text/javascript">
        function addThese(t1, t2, t3)
        {
            var v1 = parseFloat(document.getElementById(t1).value);
            var v2 = parseFloat(document.getElementById(t2).value);
            var v3 =  parseFloat(document.getElementById(t3).value);
            var total = v1+v2+v3;
            document.getElementById('output').innerHTML = total;
        }
    </script>
</head> 
<body>
    <input id="Text1" type="text" /><br />
    <input id="Text2" type="text" /><br />
    <input id="Text3" type="text" /><br />
    <input id="Button1" type="button" onclick="addThese('Text1','Text2','Text3')" value="button" />
    <div id="output"></div>
</body>
</html>
__________________
"If there is a god, I hope he has a good excuse"
Woody Allen

System: Minazo
CPU
Opteron 1210
Motherboard
Biostar TForce 550 SE
Memory
2x1GB G.Skill DDR2 800
Graphics Card
eVGA 8800GT
Hard Drive
500GB 16MB Buf Samsung
Power Supply
Corsair HX520W Modular
Case
CoolerMaster Centurion 5
CPU cooling
CoolerMaster GeminII & Scythe SFF21Ds
GPU cooling
Accelero S1 & Scythe SFF21D
OS
XP Pro SP2
Monitor
Dual monitors: 22" & 19" Widescreens
stupid is offline   Reply With Quote
Old 06-09-08   #3 (permalink)
First Time Build
 
intel ati

Join Date: Dec 2007
Location: Australia
Posts: 827

Rep: 56 wolf_08 is acknowledged by some
Unique Rep: 45
Trader Rating: 0
Default

Thanks for your help.


+1 for helping me out.
__________________
System: Xero
CPU
Q6600
Motherboard
GA-EX38-DS4
Memory
2 * 1 DDR2 800 Kingston
Graphics Card
Gecube 3870 O/C edition
Hard Drive
1 Maxtor ATA 200gigs, 1 Samsung SATA-2 500gigs
Sound Card
Integrated sound
Power Supply
OCZ 600watts
Case
Icute with side window and 25cm side fan
OS
Vista Home Premium
Monitor
View Sonic 17"
wolf_08 is offline   Reply With Quote
Old 06-09-08   #4 (permalink)
Programmer
 
stupid's Avatar
 
amd nvidia

Join Date: Jan 2006
Location: Fahaheel, Kuwait
Posts: 1,224

Rep: 144 stupid is acknowledged by manystupid is acknowledged by many
Unique Rep: 113
FAQs Submitted: 1
Trader Rating: 4
Default

No problem, glad to help out!
__________________
"If there is a god, I hope he has a good excuse"
Woody Allen

System: Minazo
CPU
Opteron 1210
Motherboard
Biostar TForce 550 SE
Memory
2x1GB G.Skill DDR2 800
Graphics Card
eVGA 8800GT
Hard Drive
500GB 16MB Buf Samsung
Power Supply
Corsair HX520W Modular
Case
CoolerMaster Centurion 5
CPU cooling
CoolerMaster GeminII & Scythe SFF21Ds
GPU cooling
Accelero S1 & Scythe SFF21D
OS
XP Pro SP2
Monitor
Dual monitors: 22" & 19" Widescreens
stupid is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 03:04 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.11725 seconds with 9 queries