473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Simple calculation (adding) in javascript

Hello,

How the heck should I make this simple summering of a data without a
submit button?

Like in an excel sheet I would like to have a couple of cells in a
column and as soon the visitor types the number the sum should change,
regardless of how many raws there are and based on the setting
(adding, multiplying etc).

I would appreciate the code, link to the code or suggestions.

Thanks in advance. :)

Apr 1 '07 #1
14 2761
wrote on 02 apr 2007 in comp.lang.javascript:
Hello,

How the heck should I make this simple summering of a data without a
submit button?

Like in an excel sheet I would like to have a couple of cells in a
column and as soon the visitor types the number the sum should change,
regardless of how many raws there are and based on the setting
(adding, multiplying etc).

I would appreciate the code, link to the code or suggestions.

Thanks in advance. :)
onchange="..."

onkeyup="...."

etc.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 1 '07 #2
ap*******@gmail.com wrote:
Hello,

How the heck should I make this simple summering of a data without a
submit button?

Like in an excel sheet I would like to have a couple of cells in a
column and as soon the visitor types the number the sum should change,
regardless of how many raws there are and based on the setting
(adding, multiplying etc).
You can use the (on)keypress event to capture the numbers the user
types. The easiest way is to simple write

yourInputElement.onkeypress = yourOnkeypressFunction;

where yourOnkeypressFunction is a function that processes the event.

--
Ian Collins.
Apr 1 '07 #3
On 2 Apr, 00:34, Ian Collins <ian-n...@hotmail.comwrote:
ap.sak...@gmail.com wrote:
Hello,
How the heck should I make this simple summering of a data without a
submit button?
Like in an excel sheet I would like to have a couple of cells in a
column and as soon the visitor types the number the sum should change,
regardless of how many raws there are and based on the setting
(adding, multiplying etc).

You can use the (on)keypress event to capture the numbers the user
types. The easiest way is to simple write

yourInputElement.onkeypress = yourOnkeypressFunction;

where yourOnkeypressFunction is a function that processes the event.

--
Ian Collins.

Thanks but I would appreciate the exempel.

Does anyone knows of the script where this is working?

Apr 2 '07 #4
ap*******@gmail.com wrote:
On 2 Apr, 00:34, Ian Collins <ian-n...@hotmail.comwrote:
>>ap.sak...@gmail.com wrote:
>>>Hello,
>>>How the heck should I make this simple summering of a data without a
submit button?
>>>Like in an excel sheet I would like to have a couple of cells in a
column and as soon the visitor types the number the sum should change,
regardless of how many raws there are and based on the setting
(adding, multiplying etc).

You can use the (on)keypress event to capture the numbers the user
types. The easiest way is to simple write

yourInputElement.onkeypress = yourOnkeypressFunction;

where yourOnkeypressFunction is a function that processes the event.
*Please* don't quote signatures.
>
Thanks but I would appreciate the exempel.
It's very easy to do, so I suggest you give it a try and learn, rather
than bodging something together from examples.

All you have to do is write a simple couple of line function to read the
value from input elements, add them and set the value of another. Bind
these to the element's onkeypress or onchange attributes and you are
done. A very good learning exercise, your textbook will show you how.

--
Ian Collins.
Apr 2 '07 #5
Thanks but I found this one instead of spending hours of learning
javascript:
http://javascript.internet.com/forms...orm-boxes.html


Apr 2 '07 #6
ap*******@gmail.com said the following on 4/2/2007 9:14 AM:
Thanks but I found this one instead of spending hours of learning
javascript:
http://javascript.internet.com/forms...orm-boxes.html
Does that site also explain how to quote on Usenet? And I would hate to
know I had to write that much bloated code to do what it does. But, you
got what you paid for.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 2 '07 #7
ap*******@gmail.com wrote:
Thanks but I found this one instead of spending hours of learning
javascript:
http://javascript.internet.com/forms...orm-boxes.html

Not good...
Mick

Apr 2 '07 #8
On Apr 2, 6:08 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>
Does that site also explain how to quote on Usenet? And I would hate to
know I had to write that much bloated code to do what it does. But, you
got what you paid for.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
Why so much negative energy?

Instead you could be more productive and type your code
that is better and more usefull than this one (that works just fine
btw) :)

Apr 3 '07 #9
On Apr 2, 7:27 pm, Michael White <m...@mickweb.comwrote:
>
Not good...
Mick
Any specific reason why?
Got better?
Apr 3 '07 #10
On Apr 3, 7:57 pm, ap.sak...@gmail.com wrote:
On Apr 2, 7:27 pm, Michael White <m...@mickweb.comwrote:
Not good...
Mick

Any specific reason why?
Open a CPU monitor. Open the page you referenced, then watch the CPU
usage climb when you put focus on one of the inputs.
Got better?
Search this group, there are hundreds of examples:

<URL:
http://groups.google.com.au/group/co...rch+this+group
>
--
Rob

Apr 3 '07 #11
ap*******@gmail.com wrote:
On Apr 2, 7:27 pm, Michael White <m...@mickweb.comwrote:

> Not good...
Mick


Any specific reason why?
Got better?
function calc(f){
f.thirdBox.value = +firstBox.value + +secondBox.value;
}

<form name="autoSumForm" action="">
<input type=text name="firstBox" onchange="calc(this.form);">
<input type=text name="secondBox" onchange="calc(this.form);">
<input type=text name="thirdBox" readonly>
</form>

But any time a user input is required you need to sanitize the entry.

Mick

Apr 3 '07 #12
Lee
ap*******@gmail.com said:
>
On Apr 2, 6:08 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>>
Does that site also explain how to quote on Usenet? And I would hate to
know I had to write that much bloated code to do what it does. But, you
got what you paid for.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Why so much negative energy?

Instead you could be more productive and type your code
that is better and more usefull than this one (that works just fine
btw) :)
Generally speaking, this newsgroup is a forum where people who are
interested in developing code in Javascript can share information.
It's not a place where somebody who has no interest in learning to
write code asks other people to do the work for them.
--

Apr 4 '07 #13
ap*******@gmail.com said the following on 4/3/2007 5:56 AM:
On Apr 2, 6:08 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>Does that site also explain how to quote on Usenet? And I would hate to
know I had to write that much bloated code to do what it does. But, you
got what you paid for.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Why so much negative energy?
Because without it to counteract all the positive energy in the universe
the universe would collapse and it would be all my fault.

Seriously, after you read about 3,000 posts from Google Groups users who
don't even come close to even trying to write code and they are asking
for someone to write the code for free, it becomes hard (if not
impossible) to maintain a positive attitude about it.
Instead you could be more productive and type your code
that is better and more usefull than this one (that works just fine
btw) :)
I do type my code, one letter at the time. Why won't I type code to do
what you want? Because I have no use for it. If you are seriously
interested in knowing what is wrong with that code, or want to learn JS,
then by all means post back and I will explain it.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 4 '07 #14
On Apr 4, 1:47 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
ap.sak...@gmail.com said the following on 4/3/2007 5:56 AM:
On Apr 2, 6:08 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Does that site also explain how to quote on Usenet? And I would hate to
know I had to write that much bloated code to do what it does. But, you
got what you paid for.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
Why so much negative energy?

Because without it to counteract all the positive energy in the universe
the universe would collapse and it would be all my fault.

Seriously, after you read about 3,000 posts from Google Groups users who
don't even come close to even trying to write code and they are asking
for someone to write the code for free, it becomes hard (if not
impossible) to maintain a positive attitude about it.
Instead you could be more productive and type your code
that is better and more usefull than this one (that works just fine
btw) :)

I do type my code, one letter at the time. Why won't I type code to do
what you want? Because I have no use for it. If you are seriously
interested in knowing what is wrong with that code, or want to learn JS,
then by all means post back and I will explain it.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
I second Randy. It would be great if people actually doing some
research before asking a question. It's even best if later the person
who was asking question, return to share his findings/solutions.
That's how the community should work.

Regards,
Hardono Arifanto
-----------------------
http://sodeve.net

Apr 4 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mx2k | last post by:
Hello @ all, we have written a small program (code below) for our own in-developement rpg system, which is getting values for 4 RPG-Characters and doing some calculations with it. now we're...
5
by: Michael Hagstrom | last post by:
Good Day - I have written a form which collects input for a fare calculation. The form collects the following: 1) Departure or Destination Group (1,2,or 3) 2) Number of Adults 3) Number of...
5
by: Mark 123 | last post by:
Hi I have a form with the input fields: ProductName Quantity and output fields: ProductPrice
8
by: rdavis7408 | last post by:
I am attempting what I would think would be a simple calculation of the cost of traveling a single mile. But I can not figure this out. The following is my script. Any help would be appreciated. ...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
2
cassbiz
by: cassbiz | last post by:
I may be in the wrong forum so Ronald don't shoot :) In my code I have an option box to choose a number - works fine. I want to carry over the new value to another field to do a recalculation. ...
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
2
by: Uncle pablo | last post by:
I was searching ALL over for a javascript to just add up a column of numbers and I found this one here in an old question. It seemed to work great for my purposes EXCEPT it stops adding at four...
12
by: brossyg | last post by:
I have a very simple price times quantity calculation. The input is STWCORQuant: <input name="STWCORQuant" class="contactitalicbold" id="STWCORQuant" onChange="javascript:STWCORPrice();"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.