checkbox Checkall jquery script

Thursday, July 19, 2012

print this page
send email








 Below code will check checkbox under form with id 'form_inbox'

var chkd=0;
    function checkall(){
        if(chkd==0)
            chkd =1;
        else
            chkd =0;
        var form = document.getElementById('form_inbox');//replace Id with form id
            if(chkd==1){           
                for(var i=0;i<form.elements.length;i++){
                    if(form.elements[i].type=="checkbox"){
                        form.elements[i].checked = true;
                    }
                }   
           
            }
            else{           
                for(var i=0;i<form.elements.length;i++){
                    if(form.elements[i].type=="checkbox"){
                        form.elements[i].checked = false;
                    }
                }
            }
        return false;
        }

You need to do only this this
<input id="InboxCheckall" type="checkbox" value="1" text="The User Alias" onclick="checkall();" name="data[Inbox][checkall]">

And don not forget to change form id.
Enjoy coding

0 comments:

Post a Comment