# Use total amount in BYO (ACBC) as part of a summation on same page.

In an ACBC study:

I want to use the total price of chosen attribute levels in a summation on the same page - as part of the 'FormatNumber' function, among other numbers.

Is this possible?
And if so; how?

Best,
Matthijs
Sawtooth Script like FormatNumber is ran on the server, so it cannot be used dynamically on a survey page.  Instead, we'll need to recreate the behavior you are after using JavaScript.  Can you describe to me how you want the formatted number to look?

Getting the code to run each time a response is changed shouldn't be too bad.  Try this script:

<script>

var interval = setInterval(function(){
clearInterval(interval);
var price = Number(\$('#[% QuestionName() %]_div .total_price .acbc_byo_price_box').val().replace(/[^0-9.]/g, ''));
}, 100);
}
</script>

If your summed price potentially includes decimals and your decimal character is not the period, line 9 would need to be updated.

Line 10 currently just shows an alert with the new price; this is what would be changed depending on what you want done with the current summed price.
Hi Zachary,

I would like the number to be in a box below the BYO exercise.
Something like:
The total amount you will pay is : [BOX]

By the way; the number that should be in the box is the sum of numbers that are a result from previous questions (through 'SetValue') en the total amount corresponding to chosen levels in the BYO exercice.

Best,
Matthijs
I'm not sure I totally understand.  The "[BOX]" amount isn't just the value pulled from the summed price box of the BYO?  Or it is and its just the level prices that fluctuate depending on previous variables?
Indeed, the amount in the "[BOX]" is not just the value pulled from the summed price box.

The amount in the "[BOX]" is (value in summed price box) + (several values that are based on answers in previous questions*)

* = These values are not listlabels but determined with the [% GetValue %] function.

I hope this makes it clear. If not, please let me know!

Best, Matthijs
I'd start by adding something like this to the ACBC, wherever you want it to appear:

The total amount you will pay is: <span class="mySummedPrice"></span>

In my script above, between lines 9 and 10, we can add the prices from previous variables.  For something like a numeric question, it would just look like this:

price += [% NumericQ %];

The code might need to be a little different if you are using a different question type to store the value to add.

Then we can replace this example alert: