View Single Post
Old 01-24-2013, 03:07 PM   PM User | #1
ARCLite Studio
New Coder

 
Join Date: Sep 2009
Posts: 73
Thanks: 5
Thanked 9 Times in 9 Posts
ARCLite Studio is an unknown quantity at this point
Question Field Count - Then Average totals HELP!

Hello everyone,

I am not a javascript programmer and if I need it usually I try to find examples on the web to build off of. But in this case I'm both pressed for time and can't find a good example. So here is what i have:

We use a PHP driven form to write HTML to file that is pre-formatted with certain "rich snippet - schema" code. Specifically it is the hreview schema. So below as a portion of the output that we need javascript to work with:

Code:
<blockquote class='description'><p><abbr class='rating hide' title='5'> 5 out of 5 Stars: </abbr>So easy to deal with! It's quite refreshing to have someone return your call so quickly. Mike was very professional! Highly recommend!</p></blockquote>
Every review that is written by the php script will have <abbr class='rating hide' title='5'> <------- this code generated, the only thing that will change is the TITLE attribute which will always be a # between 1 and 5 (This represents the star rating from the reviewer).

So what I need is a script that finds each instance of the code containing the CSS CLASS of 'rating' , looks at the # in the TITLE attribute, adds the total all together and then divides the SUM by the # of records found (basic averaging) - lastly the result of that math is assigned to a variable.

I have (I think) part of the idea figured out on how to acquire the record count of each occurrence of the CLASS 'rating' as shown below - but I can't figure out how to get the # value in the TITLE attribute and perform math on it.

Code:
<script>
var list = document.getElementsByClassName("hreview");
for (var i = 1; i <= list.length; i++) {
    document.getElementById("count").innerHTML = i;
}
</script>
Guys/Girls any help would be greatly appreciated
ARCLite Studio is offline   Reply With Quote