Is there a way to convert Flags links into check boxes within a view? I tried the Flag Form module, but it did not work (at least not in a view). I've reviewed the Flags Add Checkboxes as Display Type feature request. The discussion points to using CSS, JavaScript, or hacking the flags template file. Are there any other methods?

I'm not adverse to using JavaScript to do this, but I know little about it.

1 Answer 1


A comment from the Flag Add Checkboxes ad Display Type feature request offered a good foundation for using JavaScript. I read up on JQuery and changed the code slightly to work with D6. All credit goes to ngmaloney.

Drupal.behaviors.alter_flag_links = function (context){
    //Returns a checkbox dom object
    var cb_factory = function(class_attr, checked) {
      var checkbox = document.createElement("input");
      checkbox.type = "checkbox";
      checkbox.checked = checked;
      jQuery(checkbox).attr('class', class_attr);
      return checkbox;
    //Convert each link to a form checkbox.
    jQuery('span.your-flag-value').each(function() {
      var flag_link = jQuery(this).children('a');
      if(flag_link.length == 0) {
      flag_link.html(''); //Hide text
      var flag_classes = flag_link.attr('class');
      var checked = false;
      var class_attr = 'compare-cb';
      if(flag_classes.match(/unflag-action/)) {
        checked = true;
      //Only Add form element if it doesn't exist
      if(jQuery(this).children('input').length == 0) {
        var elem = cb_factory(class_attr, checked);
    //Attach an event listener to each of the new checkboxes
    jQuery('input.compare-cb').each(function() {
      jQuery(this).click(function() {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.