JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 17th, 2007, 11:46 PM
ventu ventu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 8 ventu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 44 sec
Reputation Power: 0
Other - Adding numbers automaticly

I would just like to know how to add 2 + numbers and have them go to set input box in an HTML form.

THanx

Reply With Quote
  #2  
Old December 18th, 2007, 10:50 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 549 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 7 h 3 m
Reputation Power: 4
adding numbers

You can not do this "automatically", the script has to repond to an "event" such as onchange, onclick, etc.
I'm guessing you want to do something like have 3 fields, 1st num, 2nd num and total.
First, create the mark-up for your form giving each input an id.
<input type="text" id="input1" ...
Then have the script get the value
var txtval1 = document.getElementById('input1');
var num1 = txtval1.value;
....
var total = num1 + num2;
var txtval3 = document.getElementById('input3');
txtval3.value = total;
__________________
WP plugins - Error Reporting, Clean Options
http://www.mittineague.com/dev/er.php
http://www.mittineague.com/dev/co.php

Reply With Quote
  #3  
Old December 19th, 2007, 02:07 PM
ventu ventu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 8 ventu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 44 sec
Reputation Power: 0
Sorry but my javascript skill is very limited Im not exactly sure how to place this. what I need is to have 3 different totals for dollar amounts. Total Drawer, Starting next day money and bag money. I need all of those to be calculated. Also since you can subtract the total drawer ot next day stat money, I would kinda need a subtraction code too.

Sorry if i'm being a pain

Reply With Quote
  #4  
Old December 19th, 2007, 02:29 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 549 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 7 h 3 m
Reputation Power: 4
where to put script

I find it convenient to put the javascript in the page's head section while I'm working on it, and then if it's used in several pages to move it into a seperate .js file. Since you're new to javascript, I think it would be best for you to break what you want to do into smaller "pieces" and when you get those working add more to it. That way you won't get overwhelmed trying to figure out the whole thing at once.
Maybe instead of getting the input field values, try "hard-coding" 2 numbers to add and get them to display in a text input. Very basic I know, but it will get you started and help make you feel cormfortable working with the DOM.

Reply With Quote
  #5  
Old December 21st, 2007, 05:07 PM
ventu ventu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 8 ventu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 44 sec
Reputation Power: 0
Hello hello, I have gotten it to work... Kinda this is my code:

PHP Code:
function addit1()
{
document.summing.totald.value =
parseInt(document.summing.onect.value) + 
parseInt(document.summing.fivect.value) +
parseInt(document.summing.tenct.value) +
parseInt(document.summing.twofivect.value) +
parseInt(document.summing.onedt.value) + 
parseInt(document.summing.fivedt.value) +
parseInt(document.summing.tendt.value) +
parseInt(document.summing.twoodt.value) +
parseInt(document.summing.fiftydt.value) +
parseInt(document.summing.hundreddt.value);

document.summing.totals.value =
parseInt(document.summing.onecs.value) + 
parseInt(document.summing.fivecs.value) +
parseInt(document.summing.tencs.value) +
parseInt(document.summing.twofivecs.value) +
parseInt(document.summing.oneds.value) + 
parseInt(document.summing.fiveds.value) +
parseInt(document.summing.tends.value) +
parseInt(document.summing.twoods.value) +
parseInt(document.summing.fiftyds.value) +
parseInt(document.summing.hundredds.value);

document.summing.totalb.value =
parseInt(document.summing.onedb.value) + 
parseInt(document.summing.fivedb.value) +
parseInt(document.summing.tendb.value) +
parseInt(document.summing.twoodb.value) +
parseInt(document.summing.fiftydb.value) +
parseInt(document.summing.hundreddb.value);

document.summing.onedb.value =
parseInt(document.summing.onedt.value) -
parseInt(document.summing.oneds.value);
document.summing.fivedb.value 
parseInt(document.summing.fivedt.value) -
parseInt(document.summing.fiveds.value);
document.summing.tendb.value 
parseInt(document.summing.tendt.value) -
parseInt(document.summing.tends.value);
document.summing.twoodb.value 
parseInt(document.summing.twoodt.value) -
parseInt(document.summing.twoods.value);
document.summing.fiftydb.value 
parseInt(document.summing.fiftydt.value) -
parseInt(document.summing.fiftyds.value);
document.summing.hundreddb.value 
parseInt(document.summing.hundreddt.value) -
parseInt(document.summing.hundredds.value)




Everything adds somewhat ok, but if I have decimals in my amount. If i had an amount of 1.33 in pennies, it would just leave it as a dollar.

Its ok if it doesn't total automatically but the decimals won't work.

Reply With Quote
  #6  
Old January 5th, 2008, 05:16 PM
mecanicu mecanicu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 112 mecanicu User rank is Private First Class (20 - 50 Reputation Level)mecanicu User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 23 m 6 sec
Reputation Power: 3
Hi ventu,
try parseDouble instead of parseInt
all the best

Reply With Quote
  #7  
Old January 8th, 2008, 12:23 PM
ventu ventu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 8 ventu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by mecanicu
Hi ventu,
try parseDouble instead of parseInt
all the best


Hey thanx, it was actually parseFloat that got me what I need. Till I had my co-workers do a test run. For some reason This problem
( .12 + .55 + 5.10 + 7.25 + 50 + 50 + 100 = 239.0199999998)

But my calculator says it equals 213.02. As you can see from my javascript its layed out right, unless my substacting is 'bleeding' into the addition but then the amount woul be lower.

I've attempted to use .toFixed(2), on my totald, totalb, totals bt still isnlt working right. Unless someone would like to help me configure this code the correct way. or at least point me to a good tutorial that would be great.

Thanx all

Reply With Quote
  #8  
Old January 9th, 2008, 12:03 AM
ventu ventu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 8 ventu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 44 sec
Reputation Power: 0
Alright, I have pin pointed the problem. If I have over .99 cents, or i guess 3 int (if you don't a '.' as one) thats when it starts to go weird.

Here is an image:

Reply With Quote
  #9  
Old January 12th, 2008, 10:52 AM
ventu ventu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 8 ventu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 36 m 44 sec
Reputation Power: 0
bump!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Other - Adding numbers automaticly


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT