SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Calculator help

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculator help

    I'm brand new to javascript and I'm muddling my way through it. I've made an online calculator that actually works pretty well except for one problem. Here's the calculator:

    http://www.oregonblackbook.com/farms/bidcalc.html

    The problem is this: if you enter numbers into the "Basic Bid" section, and then enter zeros into the "Advanced Bid" section, it should calculate the "basic bid charge" based on the numbers in the first section. The "Total Charge for Advanced Bid" should be zero, and then "total bid" should add basic and advanced together, which in this case would make it the same number as "basic bid charge". In theory anyways. But for some reason it's adding a zero on the end, an extra decimal place, and I can't for the life of me figure out why.

    Could anyone help with this? Thank you!

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    form.bidtotal.value = parseFloat(form.bbtotal.value) + parseFloat(form.adbid.value);

    Form fields' value property returns a string. Adding strings concatenates them. Your script is 'adding' the 0 from the advanced total to the string from the basic total.

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yay that fixed it! Thank you so much!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •