Fork me on GitHub

Rating

How would you rate Jimmy Stewart's Acting?

<div id="myRating">
  <input type="radio" value="1" title="A Large Pink Rabbit" />
  <input type="radio" value="2" title="Gives me Vertigo" />
  <input type="radio" value="3" title="Headed out the Rear Window" />
  <input type="radio" value="4" title="I wanna live again" />
  <input type="radio" value="5" title="It's like all wars, I guess" />
  <input type="radio" value="6" title="A Lasso Around the Moon" />
  <input type="radio" value="7" title="Merry Christmas Building & Loan" />
</div>

<p id="titleBox"></p>
YUI().use(
  'aui-rating',
  'node',
  function(Y) {
    var titleBox = Y.one('#titleBox');
    var instance, title, stars;

    var rating = new Y.StarRating(
      {
        boundingBox: '#myRating',
        disabled: false,
        label: "It's OK to be honest:"
      }
    ).render();

    rating.on(
      'click',
      function(event) {
        instance = event.target;
        title = instance.get('title');
        stars = instance.get('value');

        if (!title) {
          titleBox.set('innerHTML', 'You selected <strong>0 stars</strong> - no rating!');
        }
        else {
          titleBox.set('innerHTML', 'You selected <strong>' + stars + ' stars</strong> - "' + title + '"!');
        }
      }
    );
  }
);