HI i have 4 gridview in one form...i have to check all text field if someone select main check box...
my code is working only on one grid view..its not working on other grid view.
what should i do?
my code is

<script type="text/javascript">

 function checkAll(chkid) 
    {
        var chk = document.getElementById(chkid);



        var allchk = document.getElementsByName("contacts");
        for (var i = 0; i < allchk.length; i++) {
            allchk[i].checked = chk.checked;
        }


    }




 </script>

Regards..
Farhad

Member Avatar for LastMitch

@Farhad.idrees

i have to check all text field if someone select main check box...

You can try this (I test it on my end and it works fine the only difference is that you provided a different var than mines, so keep that in mind):

<script type="text/javascript">
    function checkedAll () {
        var chk = document.getElementsById('chkid');
        var checkboxes = [];
        var check = document.getElementByName('contacts').checked
        for (var i = 0; i < allchk.length; i++) {
            if (chkid[i].type == 'checkbox') {
                chkid[i].checked = check;
            }
        }
    }
</script>

try this common function to check or uncheck input checkbox from 'formname' form

 function checkAll(){
        var inputTags = formname.getElementsByTagName('input'); 

        for (var i=0, length = inputTags.length; i<length; i++) {
             if (inputTags[i].type == 'checkbox') {
                 if(inputTags[i].checked==true){
                    inputTags[i].checked = false;
                 }else{

                    inputTags[i].checked = true;
                 }
             }
        }

     }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.