By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,568 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,568 IT Pros & Developers. It's quick & easy.

Calculate while I type

P: n/a
Hello,
I believe that this has been answered somewhere but I cannot find it. I
have 51 textboxes on page. In 50 I can enter value. 51st should tell me
what is average of entered numbers.

As user types I want script to iterate trough form count and sum
non-empty fields and than divides this two numbers.I need to sum values
from fields that have value (not emty fields) and to divide this number
by number of non empty fields. This should occur on every change in any
of those 50 textboxes so to have live preview of average.

I'm really new to JS and I don't know even how to sum these numbers.

Thanks for response.

Jun 29 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
wrote on 29 jun 2006 in comp.lang.javascript:
Hello,
I believe that this has been answered somewhere but I cannot find it. I
have 51 textboxes on page. In 50 I can enter value. 51st should tell me
what is average of entered numbers.

As user types I want script to iterate trough form count and sum
non-empty fields and than divides this two numbers.I need to sum values
from fields that have value (not emty fields) and to divide this number
by number of non empty fields. This should occur on every change in any
of those 50 textboxes so to have live preview of average.

I'm really new to JS and I don't know even how to sum these numbers.


Use
<input onkeyup='calculate()' ..
on each input.

Summing two numbers goes like ths:
result = n1 + n2

Sorry I am not going to write your code.
If you do not try, take a comercial programmer.
If you try, we are here to help some way.

Why use a textbox for output, that look kind of silly,
textboxes are for input.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 29 '06 #2

P: n/a
mi*********@gmail.com said the following on 6/29/2006 1:27 PM:
Hello,
I believe that this has been answered somewhere but I cannot find it.
Then you didn't look in the right places, or, it hasn't been answered
before but odds are it has been answered before.
I have 51 textboxes on page. In 50 I can enter value. 51st should tell me
what is average of entered numbers.
Easy enough.
As user types I want script to iterate trough form count and sum
non-empty fields and than divides this two numbers.
There is a better way to track that than looping through 50 form
elements every time one gets changed.
I need to sum values from fields that have value (not emty fields) and to
divide this number by number of non empty fields.
And if the value is not a number?
This should occur on every change in any of those 50 textboxes so to
have live preview of average.
OK. Average on the fly.
I'm really new to JS and I don't know even how to sum these numbers.


You could start with the group FAQ and the section that asks "Why does
1+1=11"?

<URL: http://jibbering.com/faq/#FAQ4_21>

Then, post your best effort and go from there.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 29 '06 #3

P: n/a
Thank you so much for your kind responses. I really don't expect that
anyone writes code for me, but I do expect than someone more
experienced can tell me the right direction.

Jul 3 '06 #4

P: n/a
wrote on 03 jul 2006 in comp.lang.javascript:
Thank you so much for your kind responses. I really don't expect that
anyone writes code for me, but I do expect than someone more
experienced can tell me the right direction.
Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 3 '06 #5

P: n/a
mi*********@gmail.com said the following on 7/3/2006 8:27 AM:
Thank you so much for your kind responses. I really don't expect that
anyone writes code for me, but I do expect than someone more
experienced can tell me the right direction.
I gave you that direction. You either didn't see it or chose to ignore it.

onchange="totalFieldReference.value += this.value"

That is as good a start as you will get. Test it, tinker with it, try to
reason it out.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 4 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.