Ranking - Part II

© 2011 By: Dov Trietsch. All rights reserved

Ranking Part II

In my introduction to ranking I also introduced the. This is actually a much more sophisticated program than the one we need to simply rate an item, but it introduced you to the sophisticated results that you may achieve by a bit of code and accompanying CSS.

In this installment, I am going to handle simple rating with 5 stars. The extra sophistication will come in the form of creating new elements in run time. Why do I need this? I like to be able to extend the SharePoint New and Update forms and put the starts in them simply by using the code shown here. We do not even need to go into SPD. We may achieve this simply by adding a content editor web part; more about this in the next installment.

I have created a new page – – in which you may praise me in 5 different ways, but not immediately. The ranking mechanism – the 5 stars – has to be created first. To achieve that, click the “Add Element” button on the screen and then proceed in giving me the appropriate number of stars.

Now view the source and see how this extra 5 start element was added. Also see how the ranking is achieved. This, obviously, is not any different in principle than what we did in the Ranking game.

We create some sophisticated HTML, Add some style and create the element by:

var divString = "

                   

"; m = document.createElement("p"); m.innerHTML = divString; m.className = "blah"; function AddElement {     y = document.getElementById("Rest");     y.parentNode.insertBefore(m, y); }

When you look into the full code, you’ll notice that I have added an empty

into the form. A div element, like p, creates a line break, but the main purpose here was to mark the place above which I wanted to add the stars.

Now you may hover over the stars, see how they behave and click on one of them to see that the program can react to your selection.

That’s all folks!

This article is part of the GWB Archives. Original Author: PointsToShare

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.