• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Is it possible to do math with web app tags?

New Here ,
Oct 15, 2013 Oct 15, 2013

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.

TOPICS
Web apps

Views

946

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 15, 2013 Oct 15, 2013

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2013 Oct 15, 2013

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 16, 2013 Oct 16, 2013

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 16, 2013 Oct 16, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 16, 2013 Oct 16, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 16, 2013 Oct 16, 2013

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 17, 2013 Oct 17, 2013

Copy link to clipboard

Copied

It throws an

Uncaught ReferenceError: $ is not defined

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 17, 2013 Oct 17, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 17, 2013 Oct 17, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines