9 Replies Latest reply on Oct 17, 2013 6:38 PM by TheBCMan

# Is it possible to do math with web app tags?

I need to take the average of 5 numbered values.    {tag_average} = ( {tag_1} + {tag_2} + {tag_3} + {tag_4} + {tag_5} ) \ 5        is what I need to do.

• ###### 1. Re: Is it possible to do math with web app tags?

Hey there, You will need to use javascript for that.

DO you know how to code in javascript and use something like jQuery?

• ###### 2. Re: Is it possible to do math with web app tags?

I have a little bit of experience but its been a while. this is all I have so far:

<script type="text/javascript">

var a= {tag_a}

var b= {tag_b};

var c=  tag_c};

var d = {tag_d };

var e = {tag_e};

var overall = (a + b + c + d + e) / 5;

</script>

• ###### 3. Re: Is it possible to do math with web app tags?

What do you want to do with the result?

(by the way you do not need to make multiple posts asking the same thing)

• ###### 4. Re: Is it possible to do math with web app tags?

I just want to output the result back on the page.

• ###### 5. Re: Is it possible to do math with web app tags?

To where, a container?

You using jQuery or just doing normal javascript?

if normal javascript it would be using document.write into a targeted element with ID etc.

Devil is in the details here.

• ###### 6. Re: Is it possible to do math with web app tags?

Insert both into your page, put the HTML where you want the average text to be. I re-wrote your calulation in case any of the tag's don't have a value (although I assume a number) and incase you try to divide by zero.

Javascript:

<script type="text/javascript">

Doit=function(el){

var a= {tag_a} || 0;

var b= {tag_b} || 0;

var c=  tag_c} || 0;

var d = {tag_d } || 0;

var e = {tag_e} || 0;

var overall = (a + b + c + d + e) / 5;

if (overall==0){overall=''}else{overall/=5};

\$(el).html(overall);

}

</script>

HTML:

<span id="averagehere"></span>

• ###### 7. Re: Is it possible to do math with web app tags?

It throws an

Uncaught ReferenceError: \$ is not defined

• ###### 8. Re: Is it possible to do math with web app tags?

Because BCMan assumed your running jQuery which you are not hence why I did not jump into giving you code and asked you a couple of questions first

• ###### 9. Re: Is it possible to do math with web app tags?

Yeah assumed, include it from google in your page and you're good, so many pages on the net have the google jquery include on them I guarantee you already have it sitting in your browser cache so there is no performance hit including the LIB.