Simple calculation (adding) in javascript

Discussion in 'Javascript' started by ap.sakala@gmail.com, Apr 1, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Evertjan. Guest

    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)
     
    Evertjan., Apr 1, 2007
    #2
    1. Advertising

  3. Ian Collins Guest

    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.
     
    Ian Collins, Apr 1, 2007
    #3
  4. Guest

    On 2 Apr, 00:34, Ian Collins <> wrote:
    > 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, 2007
    #4
  5. Ian Collins Guest

    wrote:
    > On 2 Apr, 00:34, Ian Collins <> wrote:
    >
    >> 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.
     
    Ian Collins, Apr 2, 2007
    #5
  6. Guest

    , Apr 2, 2007
    #6
  7. Guest

    On Apr 2, 6:08 pm, Randy Webb <> wrote:

    >
    > 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, 2007
    #7
  8. Guest

    On Apr 2, 7:27 pm, Michael White <> wrote:

    >
    > Not good...
    > Mick


    Any specific reason why?
    Got better?
     
    , Apr 3, 2007
    #8
  9. RobG Guest

    On Apr 3, 7:57 pm, wrote:
    > On Apr 2, 7:27 pm, Michael White <> wrote:
    >
    >
    >
    > > 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/c...=form input add values&qt_g=Search this group
    >


    --
    Rob
     
    RobG, Apr 3, 2007
    #9
  10. Lee Guest

    said:
    >
    >On Apr 2, 6:08 pm, Randy Webb <> wrote:
    >
    >>
    >> 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.


    --
     
    Lee, Apr 4, 2007
    #10
  11. On Apr 4, 1:47 pm, Randy Webb <> wrote:
    > said the following on 4/3/2007 5:56 AM:
    >
    > > On Apr 2, 6:08 pm, Randy Webb <> wrote:

    >
    > >> 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
     
    Hardono Arifanto, Apr 4, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Badass Scotsman
    Replies:
    1
    Views:
    368
    S. Justin Gengo
    Apr 24, 2006
  2. Replies:
    2
    Views:
    377
    Steven D'Aprano
    Mar 4, 2007
  3. Fredrik Lundh

    Re: Simple calculation error

    Fredrik Lundh, Jan 4, 2008, in forum: Python
    Replies:
    2
    Views:
    350
    Francois Liot
    Jan 4, 2008
  4. serkany
    Replies:
    6
    Views:
    1,157
    JohnDuq
    Apr 17, 2009
  5. Replies:
    9
    Views:
    138
    Randy Webb
    Jan 25, 2006
Loading...

Share This Page