How to checkall only filtered items in the list
I have a Search Filter for Check box List using Jquery and java Script....Also i have Checkall and UncheckAll radio buttons..If i enable CheckAll button...it will check all checkboxes in that list...If i filter the list using search filter, also it will check all checkboxes in that list...
Now i want to check only filtered items in the list should checked, if i click checkall.... If i not filter means it will check all items in the list...
My codings are below...
CheckAll coding:
<script>
function checkall(formname,checkname,thestate)
     {
            var el_collection=eval("document.forms."+formname+"."+checkname);
            for (c=0;c<el_collection.length;c++)
                el_collection[c].checked=thestate
     }
</script>
Search Filter Coding:
    <script>
    (function ($) {
      jQuery.expr[':'].Contains = function(a,i,m){
          return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
      };
      function listFilter(header, list) {
        var form = $("<form>").attr({"class":"filterform","action":"#"}),
            input = $("<input>").attr({"class":"filterinput","type":"text"});
        $(form).append(input).appendTo(header);
        $(input)
          .change( function () {
            var filter = $(this).val();
            if(filter) {
              $(list).find("a:not(:Contains(" + filter + "))").parent().slideUp();
              $(list).find("a:Contains(" + filter + ")").parent().slideDown();
            } else {
              $(list).find("li").slideDown();
            }
            return false;
          })
        .keyup( function () {
            $(this).change();
        });
      }
      $(function () {
        listFilter($("#header"), $("#list"));
        listFilter($("#header1"), $("#list1"));
      });
    }(jQuery));
</script> 
<script type="text/javascript">
function show()
{
 if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","location.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;
    var x=xmlDoc.getElementsByTagName("value");
    for (i=0;i<x.length;i++)
    {
     var name=x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
     var link = document.createElement( "a" );
     var list = document.createElement( "li" );
     var cb = document.createElement( "input" );
     cb.type = "checkbox";
     cb.id = "c1";
     cb.value = name;
     cb.name="v1";
     cb.checked = false;
     link.appendChild(cb);
     link.innerHTML+=name;
     var lists=document.getElementById('list');
     list.appendChild(link);
     lists.appendChild(list);
     }
}
</script>
My body Tag codings:
<form id="tracklocation">
    <ul id="list" style="list-style:none">
    </ul>
     <h1 id="header1">DVD Collection</h1>
    <input type="radio" value="ca" name="dt" onclick="checkall('tracklocation','v1',true)">Check All  <input type="radio" value="ua" name="dt" onclick="checkall('tracklocation','v1',false)">Uncheck All
  </form>
How to checkall only filtered items in the list..please help me....
This doesn't answer your question but it's much better formatted as an answer than a comment.
Please don't use eval where square bracket notation is by far the better option. Where you have:
> var el_collection=eval("document.forms."+formname+"."+checkname);
presuming that checkname is the name of a radio button set, then it should be:
var el_collection = document.forms[formname][checkname];
 Note also that if there is only one such input, el_collection will be a reference to that element and not an HTMLCollection, so you should check for that.  
使用Jquery更改checkall函数,它会正常工作....
function checkall(formname,checkname,thestate)
{
    if ($('li').is(':hidden')) {
        var visible = $('input[type=checkbox]:visible').each(function() { 
                         this.checked = thestate; }
                       );
    }
    else
    {
        var visible = $('input[type=checkbox]').each(function() { 
                         this.checked = thestate; }
                       );
    }
}
                        链接地址: http://www.djcxy.com/p/71032.html
                        上一篇: 如何使用jQuery处理复选框的更改?
下一篇: 如何仅检查列表中的过滤项目
