Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying rateit jquery plugin to a select box

I have the following select form element, and I want to apply the rateit jquery plugin to it.

<select class="test" id="Rating" name="Rating">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>

and I am trying to apply the plugin using $("select.test").rateit();, but despite fireQuery showing data attached the the select element that, no effect is made and I am still left with a select box, and not a line of stars.

EDIT

CSS File is included

Here is the page in question

like image 672
Mild Fuzz Avatar asked Jan 29 '26 00:01

Mild Fuzz


1 Answers

You're using the plugin wrong. See very simple example: http://jsfiddle.net/rudiedirkx/ZuJ2k/

The select has to be there, but you still have to reference the div when you call the plugin: $('div#rating2').rateit();

The div then has a reference to the select with a data attribute: data-rateit-backingfld="select#Rating"

edit
Actually it looks like you're not using the plugin at all? Where do you call the plugin?

edit
This is your code:

rateItDiv = $('<div class="rateit" data-rateit-backingfld="#Rating"></div>');
$("div#ReviewInputZone select.test").after(rateItDiv);
$('div#rateit').rateit();

On the last line, you reference div#rateit, but that div doesn't exist. You just created a div.rateit, not a div#rateit. Change either of those to the other, and it should work. I'd keep the # because that's slightly faster (but you'd have to be sure there's only one of these rateit dropdowns on a page).

So the new first line:

rateItDiv = $('<div id="rateit" class="rateit" data-rateit-backingfld="#Rating"></div>');

edit
Also, you can test it before you change any code. Just open your Javascript console (Firebug in FF or Developer tools in Chrome) and type: jQuery('div.rateit').rateit();

like image 135
Rudie Avatar answered Jan 30 '26 12:01

Rudie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!