4 Replies - 450 Views - Last Post: 30 April 2013 - 06:59 PM

#1 nakins  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-May 09

Trying to get cumulative total of dollar amounts

Posted 30 April 2013 - 02:38 PM

Hi again,

Below is code I'm trying to write that will get the values of hidden inputs. and display a total. This is only for one input, but I start with a 0 value and the first input has a $1.00 value. So, with just this one bit of code, the total should display as 1.00, but only shoes 0.00. I can display the price of item one (feature1price). But I can't seem to get it to add to the total. Any suggestions on how to do this?

Thank you,

function totalamt(){
     var total = 0;

     var item1 =  document.getElementById('feature1name').value;
     if(item1.value == "on"){
          var price1 = document.getElementById('feature1price').value;
          total += parseFloat(price1);
          }
     document.getElementById('item1').innerHTML = document.getElementById('feature1price').value; 
     document.getElementById('totalAmount').innerHTML = total.toFixed(2);     
}


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to get cumulative total of dollar amounts

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3561
  • View blog
  • Posts: 10,358
  • Joined: 08-June 10

Re: Trying to get cumulative total of dollar amounts

Posted 30 April 2013 - 02:40 PM

from the result it looks like the condition is not triggered. (but that’s impossible to say without the HTML)
Was This Post Helpful? 0
  • +
  • -

#3 nakins  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-May 09

Re: Trying to get cumulative total of dollar amounts

Posted 30 April 2013 - 02:57 PM

<body onload="totalamt()">
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3561
  • View blog
  • Posts: 10,358
  • Joined: 08-June 10

Re: Trying to get cumulative total of dollar amounts

Posted 30 April 2013 - 02:59 PM

ok, one more error: line #5, a string does not have a value property.
Was This Post Helpful? 1
  • +
  • -

#5 nakins  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-May 09

Re: Trying to get cumulative total of dollar amounts

Posted 30 April 2013 - 06:59 PM

Thanks, that got it working.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1