0

I am tring to add 2 values together in a javascript application however when I try and do this the output I get is;

Total Price £[object Object]116.96

Where [object Object] is the value I am trying to add to 116.96 the code I am using to do the addition is bellow;

    document.getElementById("getTotal").addEventListener("click", function()
{
  var STotal = (($('#SeatPrice')+(subTotal)).toString());
  $('#total').text(STotal);
});

these are where the values for '#seatPrice' and '#total' are derived from

  $('#total').text(subTotal.toString());
  $('#SeatPrice').text((($('td.selected').length)+count)*pricing);

If anyone has any ideas on how to resolve this issue please let me know. Thanks!

1
  • Well you have a jQuery object, what part of that object do you want to add to the number? Is it an input, a div, a data attribute? Commented Feb 24, 2016 at 14:43

1 Answer 1

3

The problem lies here: var STotal = (($('#SeatPrice')+(subTotal)).toString());

$('#SeatPrice') is a jquery function which returns an object - the html element you've searched for. So when you add that to your subTotal, you are adding the object to a string which, in javascript, will just create a string out of both.

You probably want to get the value of that element using something like $('#SeatPrice').val() or $('#SeatPrice').text()

Sign up to request clarification or add additional context in comments.

1 Comment

just what i was looking for! Thanks @millerbr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.