1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript adding values from textboxes after onChange event

Discussion in 'JavaScript' started by rf2005, Aug 27, 2010.

  1. #1
    Hi All,
    I need some assistance with this I have several texboxes that store a integer, and after each value is placed, i'd like to place the total into a separate textbox.

    Thanks in advance.
     
    rf2005, Aug 27, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is pretty crude but it works most of the time :)
    
    <html>
    <head>
    <script type='text/javascript'>
       function sumValues() {
          var v1 = parseFloat(document.getElementById('box1').value);
          var v2 = parseFloat(document.getElementById('box2').value);
          document.getElementById('box3').value = v1 + v2;
       }
    </script>
    </head>
    <body>
    <form onchange=sumValues()>
    <input id='box1' type='text' />
    <input id='box2' type='text' />
    <input id='box3' type='text' />
    </form>
    </body>
    </html>
    
    Code (markup):
     
    Cash Nebula, Aug 27, 2010 IP
  3. rf2005

    rf2005 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. It works great!!!!
     
    rf2005, Aug 27, 2010 IP