SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question need checkall/uncheckall js function

    hello , i have main checkbox button . i want the function which do check all checkboxes inputs and at the same time when uncheck main check button it uncheck all checkboxes inputs

    thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Code javascript:
    function setCheckboxes() {
    	var els = document.getElementsByTagName('input'),
    		elsLen = els.length,
    		i;
    	for (i = 0; i < elsLen; i+= 1) {
    		if (els[i].type === 'checkbox') {
    			els[i].checked = this.checked;
    		}
    	}
    }
    document.getElementById('main').onchange = setCheckboxes;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    North Richmond
    Posts
    495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regards,
    BJ Duncan

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    You could even have a button that uses the setCheckboxes() function to uncheck them.

    Code javascript:
    function uncheckAllCheckboxes() {
    	setCheckboxes.call({checked: null});
    }
    document.getElementById('uncheck').onclick = uncheckAllCheckboxes;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •