JavaScript function only selects first checkbox when told to pre-select more
<p>I have a JavaScript function that dynamically creates checkbox elements when some value from a select box is selected. To verify if a checkbox is checked or not, from PHP I send a variable. </p>

<p>For example: <code>var_id=1,2,3,5</code>. I use <code>jQuery.inArray</code>, but I have checked only first checkbox checked from list of five.</p>

<p>This is the function that creates the lis of checkboxes:</p>

<pre><code>function outcheckboxes(_id, _text, var_id) {
  (function($){
    var topicContainer = jQuery('#classificationss_id');

    topicContainer.append(
        $('&lt;li /&gt;')
        .addClass('checkboxclassid')
        .append(
            $('&lt;input /&gt;', {
            id:      'classid' + _id,
            name:    'classid[]',
            value:   _id,
            type:    'checkbox',
            checked: !$.inArray(_id, var_id)
            })                                      
        )
        .append(
            $('&lt;label /&gt;', {
            'for':  'classid' + _id
            }).text( _text)
            )
        )
    })(jQuery)
}
</code></pre>

<p>I call the function <code>outcheckboxes</code> from an other function :</p>

<pre><code>function Classifications(obj_parent, obj_this, obj_child, var_id) {

        var catalog_id = jQuery("#"+obj_parent).selectedValues()[0];
        jQuery("#classificationss_id").children().remove();
        jQuery("#"+obj_this).children().remove();
        jQuery("#"+obj_child).children().remove();


        if(catalog_id&gt;0){
            jQuery.ajax({
                type : "GET",
                url : "../index.php",
                data : "option=com_namecat&amp;view=lists&amp;format=raw&amp;list=classifications&amp;id=" + catalog_id,
                dataType : "xml",
                success : function(xml) {
                    var _id = "";
                    var _text = "";

                    jQuery(xml).find("row").each( function() {
                        _id = jQuery(this).find("id").text();
                        _text = jQuery(this).find("text").text();
                        jQuery("#"+obj_this).addOption(_id, _text );

                        outcheckboxes(_id,_text,var_id);

                    });
                }
            });
        }
}
</code></pre>

<p>Where am I going wrong?</p>
