0

I have a fiddle here: my fiddle. What I am trying to do is create a list of items from a separate group of lists. I cannot seem to get a grasp on what I am doing wrong, but here is whats happening:

  1. I have a group of lists based on tabular data
  2. Each list has the name of the column and a selection checkbox
  3. If I select an item, it needs to be added to the selected columns area (vertical list)
  4. There are 14 unique tabular items with checkboxes
  5. (PROBLEM -->) When I select an item, it gets added 14 times in the selected columns section

code

(html):

I tried ti insert HTML but is not working right. Please look at the fiddle listed above.

(jquery):

var dte = // drag table elements
{
init: function() {
    var chkbx = $('.group input[type="checkbox"]:checkbox');
    //var chkbx = $('#accordion');
    for (var i = 0, ii = chkbx.length; i < ii; i++) {
        $(chkbx).bind("click", dte.adjustList);
    }
},

adjustList: function(event) {
    var list = [];
    var str = '';
    var eleval = event.currentTarget.value;
    var eleid = event.currentTarget.id;
    if (eleval == 1) {
        list.push(eleid);
        str = '<li>' + eleid + '</li>';
    }
    $('#vertical ul').append(str);
/*
    //var ele = event.currentTarget.id;
    var allVals = [];
    var str = '';
    //var obj = $("#"+ele);
    var ele = $('#accordion');
    $(obj+': checked').each(function(){
        allVals.push($(this.val()));
        dte.list.push($(this.val()));
        str += '<li>'+$(this.val())+'</li>';
    });
    $('#verticle').text(str);
    alert('List: ' + toString(list));
    */
}
};
dte.init();
2
  • jsfiddle.net/deerua/LxwLf/1 Commented Jun 14, 2012 at 13:36
  • $('.group input:checkbox') == $('.group input[type="checkbox"]') Commented Jun 14, 2012 at 13:41

4 Answers 4

2
init: function() {
    $('.group input:checkbox').bind("click", dte.adjustList);
},
Sign up to request clarification or add additional context in comments.

2 Comments

This is the first and the best answer. +1
As always, I am always over thinking the problem. Thanks for all your help. This did the trick
0

you only need to bind once based on your selector.

init: function() {
        var chkbx = $('.group input[type="checkbox"]:checkbox');
        $(chkbx).bind("click", dte.adjustList);
 },

fiddle

Comments

0

I have edited your fiddle, I removed the for loop. Here is the link updated fiddle You only need to bind the click event once.

Comments

0

You are binding events multiple time. You can do something like this:

init:function(){
  $('.group input[type="checkbox"]:checkbox').bind('click',dte.adjustList);
},

Edited your fiddle:

http://jsfiddle.net/emphaticsunshine/tPAmc/

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.