Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hey there, You will need to use javascript for that.
DO you know how to code in javascript and use something like jQuery?
Copy link to clipboard
Copied
Thanks for the reply Liam,
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>
Copy link to clipboard
Copied
What do you want to do with the result?
(by the way you do not need to make multiple posts asking the same thing)
Copy link to clipboard
Copied
I just want to output the result back on the page.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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">
$(document).ready(function(){ Doit('#averagehere'); })
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>
Copy link to clipboard
Copied
It throws an
Uncaught ReferenceError: $ is not defined
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.