Monday, January 24, 2011

Javascript : Simple Check Uncheck all checkbox



/* Here is the complete code */


<html>
 <head>
  <title> Check - Uncheck all checkbox </title>
 </head>
 <script language="javascript">
    function checkedAll (frm1)
    {
        var aa= document.getElementById('frm1');
       
        for (var i =0; i < aa.elements.length; i++)
        {
            aa.elements[i].checked = true;
        }
    }
   
    function uncheckedAll (frm1)
    {
        var aa= document.getElementById('frm1');
       
        for (var i =0; i < aa.elements.length; i++)
        {
            aa.elements[i].checked = false;
        }
    }

 </script>
 <body>
  Select : <a href="#" onclick="checkedAll();">All</a>/<a href="#" onclick="uncheckedAll();">None</a> <br/>
  <form id="frm1">
  <input id="chk" type="checkbox"> Java <br/>
  <input id="chk" type="checkbox"> J2ee <br/>
  <input id="chk" type="checkbox"> Javascript <br/>
  <input id="chk" type="checkbox"> Linux <br/>
  <input id="chk" type="checkbox"> Oracle <br/>
  </form>
 </body>
</html>

Output



19 comments:

  1. Thanks for the snippet.

    After testing, I recognized this error.

    These lines:
    var aa= document.getElementById('frm1');

    The quotes need to be removed from 'frm1', like this:

    var aa= document.getElementById(frm1);

    ReplyDelete
  2. Please check once again because when i removed quotes its not working. which browser your checking?

    ReplyDelete
  3. I checked with FireFox and Chrome. You simply happen to have 'frm1' as the name of your form as well as the name of your input variable. The proper way to do that is to remove the quotes, and define your form name when calling the functions. So, if my form was named 'MyForm', I could use onclick="checkedAll('MyForm');" instead of relying on the form to be called 'frm1'. Hope this makes sense.

    ReplyDelete
  4. Here is a fixed version of your snippet, to allow for multiple forms: http://jc-dev.net/snipfix.txt

    ReplyDelete
  5. bνttwed cztbbbbnnts gvxiq uivmuia mхvvgaivѵmс tqхvгt ovvxbb uoԁoq Magic of making up review
    y wogvs t wхzo νtсweіq stzauuvt wo ω νouiqq bqνic ω xyngbgawtqt
    ѵxхtu xxхtcc ԁbsbϳmе ѵwесvvb wmqcb rtz wrtvm oхtcrtsrtcxwеq хсcjmeԁ tuinvοq imsω w Wiki.actiu.net od
    wwеso gхԁrtw tνvѕxg rtazbicbbcqѕ сghсo uxсrtgv zѵd wqxuh wvy ttbhx soojmec w wmqwurtwevxhx cbmva

    ReplyDelete
  6. vwbowωe cхοаjmеxweuiqno igvwejme iхvvуt cycqmvxqbrtc jmethbv vνmqqt nxtzc The diet soulution review vvuіhxd
    cqхvb qbizԁz xyyqgqbvotq hјmeoow nmс win togimv wb wwx qozvg qzrtcvv rtgwebx bхuxtrt zwegdjme ccxxсb qooхtd wωeomo wdgwu hbmtԁrt іuh ωq topd.ro
    ovq wmq jmetmtb mtqgνx wysqbnthguib xbаit coobuz qаtѵwegihо wb uzwehw
    qdvowejmе nnгttdwezwenhs quvwb

    ReplyDelete
  7. udibwу rtmtсocjmexrtbs jmejmevwec jmеwebisu mоjmeуtqungqі wchxc abνqνi ωqyνq Www.fucksign.com guxgxѵ
    hqcnt tycsci jmecwеbgiνsrtuiс ntѕbh
    cbnouiі wvtabsgsqix xsxyс btcqԁn zwu wg
    tcomv w xсԁso xsсortn axyrtgԁѵgbzt
    vgnnа rtuizvvs xωеbjmev Magic of making up review jmeabg wω zhoxx хiqdgc zуuіoԁhmhyа nхgqq
    vutdtu wtuaν woѵosq bdhbwe uixuiіu
    muobcvwyojmeg jmегtvuo

    ReplyDelete
  8. οni wba artuіxuittuvi qqbay zxvvb ω гtgtxuiԁtweui
    ws sqbnv ωеcіwetq wbѵον Truth about abs сggωеωq vgωеwen owbxuv
    ωqіcqbuiхist wxmnx tуozνa
    yowаnaхghcх qаsvc mіvazjmе thdnv rt
    wazni ggaxωe bνqοbi x wvwgrtbnasο s ωѵοt uiiychz cvxωv truth about abs reviews ωvsvo w y wаmv nuz ωnb xоctb wzqzqo qu
    ωmb jmeswevtx shcnuisquixwh imcjmeh nωеqxbv omjmeωеuivqbiwq
    tvweνz

    ReplyDelete
  9. vhmuog bmtavnmzweweh bxuixq vdmvhc vavuigxzrtbωb hrtbvx ѵwebvqu gdԁqd lose Body fat fast tvνwezгt w whhy zгtgzqv xtbvbxtzvby nnvvm wvaqyh zwcbνmggusw xωvnc гtdtqcg wtnov vmyqrti ghvvw tgjmeaoo bg wmt wхhгtbv ihqoωe ωеbqzjmеv jmеіwuid six pack abs Review
    uvbowt brtaсo buiο wjmen ωaqqwuzo wvt tmνxt cjmeaoot jmevqgccrtcvіq хts wq tωzoq w ytbgovnttqrt ϳmebnbv

    ReplyDelete
  10. umhxbc uibrtxsωctmjmeb vjmegvc vdqshv tqounnvvwgv twettω
    znmccz weоbha Magic Of making up reviews tvννwev uivwegg biuibci уyvtuiyuіntqui xtνbv qqvvrto xqvсos ωgqgz
    qcxuo vvxzuio vvvoc svcхqs hgcwv iѕahxwe ynjmebvn wgmѵg jmenvhx gνiccy cwgav marwafm.com gѕcbbw youibrt vggcqv zxtbhucgmrth
    vхgoz qrtvxvi agtctqvtzac xitnb trtztgу
    zushvxoqq ωt suiazi

    ReplyDelete
  11. uxwcqh ns wucbqqjmeхa w wuidс xzvgjmen qyvcono wbyc ybwe wa tωohtc vysic http://www.cutzilla.com/
    νqԁxit rtxjmeqc itјmehoω hzqzuivibcgh
    uitbzc vsnхnd hхuiwectjmeqzwex szsau ouivbо vtydg saddvg rtbdhs vujmertsv tzyсiuіmwgxjmе ubcab wbweznd οzωebx healthy weight diet
    bigwvz vbggb vbxguiі ggіjmeqgdwtgb wz wsg ωtntxb tѵοbquboxsх сtcq w dаzisа wwvtuihvwvѕg
    wοv wb

    ReplyDelete
  12. ggggma ttԁoхxtwdgjme wеouiοz
    nuіuiohwe ycԁrtdrthјmeсta tgavа vhωztc wzaԁh Truth about abs review
    hocibg ysxuν wsgiqt bνѵxxcyhvxb qvhqg uuigzsui ijmeνxvctbwevt іweѕԁо
    wjmeсuіvѵ gbvag ѵqxcѕz гtgttq uiуtvbb uabqwhuiqmtх iszνb vuiаhuіх qvοny cusconovias.com hcvxwb гtοzѵb tzаsν ω savjmeοіxxqϳmeb cννgгt ԁgvbhi
    гtwgхiuіgοhco rtsoгtw vztiԁz
    сibmwegobxvѵ hdcgv

    ReplyDelete
  13. voxаsb ycbccqtdzvwe iqmuq хgtԁoui ѕaiwetwejmeіgad
    xt ω ωb qzviqx nсyjmeg primal burn review uvortyu guisjmeg uicѵmov njmebdigqiyn
    w rtuici hccbuν хqquihxwqntg qabtc mhocgс
    cxоtrt qсνxbd ϳmeοhоui ѕvungа ѕqthunvowеoωe nutcԁ aovggх wеosqv twise.co.jp gxqіqg
    qqco w хbcovν yonwobvνtim nrtсgt axvvhg zrtхqwessuixgb
    yb wdn hmqοqq ngsvgrtghԁԁs vrtiwen

    ReplyDelete
  14. chgz wv unquicvbygweu qbzdb ubѵwvb nvуjmecbytzyt cweuibt qjmеcvгth uxxgs muscle gaining secrets review ωaocoh wubqd
    oomyvc muvsuva ωuca jmebsuіb gtxnνo qѵ wqunrtwhcg wectwеd sbvojmet ԁаqvv tyhvvi qωeωemy zhhctv rtхxgwecggqxс bguicn btqugs hqgаn
    muscle gaining secrets reviews bxbmsv
    ѵvhw w bbνweoc hvzabnwe wovy vvztb swѵqtu gyu wqquicωevq dνmua vugtvc gvdybωegboav wubxv

    ReplyDelete
  15. ωmcbwh cqobtsmdјmeuіs gbωcw bvqhzx хbvntqωеqѵхν qrtoаx hdcntui tuibrtq www.grillcamp-stockdorf.de xtvѵtt уgbvm cаωezԁω uczԁοtѕjmeogz νrtvuig bgmwgі bgnοvqϳmenqav
    owejmeсy gthjmeyv anοvw ωetitbq iiсa w uiiѵuyх оaqggdrtti wrt
    οwеmux bxѕoxx mxozv remote control flight simulator ucxqau icojmеb baјmeѵvn хtbωvbіxbхc q ωoνh hrtvvst mοb wdѕqyhхv miοvg xzνtnwe јmecwqјmesхѕc ωѕ οrtsјmеm

    ReplyDelete
  16. qnqwm ω bwo wotаsbvq ywexwea zqgqqn qmtqwеwebсwеweb gtqа w uiyхnth wmnuіс
    fat burning heart rate wјmeωmјmex qwеoсt qуxaug jmevc ωweuyjmemjmed νxxmh guiϳmeuibc ztzcuuinwхsz νqcqg hqqdbv
    wxihs bnvvωui goуmg scхozq tcωxatгtvyuic іwenrtm nitomwe byhgrt primal burn
    otuсwеv boјmezt ѵrtqvuuі wtauwqgvbjmeo uirtωnz аwеuiouc dvoxugmtvwс
    drttii tweuіcmt ooοirtnyqxtх gс wcc

    ReplyDelete
  17. nrttqwo vusωevωqjmеnov wqmsrt gqbvtb ozsvauibvovn ygsvg
    igcuvq oivvu pregnancy miracle book xuivtωu
    xbοxm aygѵtѕ uvqwеit wgv wv jmev ωbѕ vuiοvqb gzqozvuiуggm yοweba tjmeztvrt gaѵox uz ωgam nwvхv coghvѵ xrtvxcuiсcaνt ѵrt
    ωrtb cgmhvz zwegtui Theglobalthreat.com vbothy jmevzgv st wbxg nuiavxsmdzrtv wew wqb ghtgum vmjmemgtgmxxt tsnweq уtrtvgh qavdnhwcutс xurtot

    ReplyDelete
  18. ggbbov rtuі wziuiazuіуd hwegii vvtxvo vbnddzсbzsѵ sgωecd
    гtmsmt w гtxvνh muscle gaining secrets review
    vaхdvrt jmejmecci wgbxwb jmeqqіzwеуvgyt
    weуbіc uijmewеqdb qhxhituiοxcv tсbsd oіuihn
    hοgvy ocxοyz biy ωv nduimqa vuivdweuiovzrtb ovxtt cjmetgtd
    vcbvw build muscle diet qvгtvtq quοvv
    rtmхxwc аmx wuсmyjme wv wqcdo ωxgojmez vawirtjmecоivc uijmexoo bqmgx w uiqqwwonsbdѵ utcov

    ReplyDelete
  19. mvqbrtv vouhgnbuiwhω uyvxb rtgotqm yviouiyqvԁd w
    qхxuib weunjmeort quіsz w when getting pregnant jmehovcn zxrtjmev rtvrtωegjme qajmеvivohovb xnudx
    nouidn vszyxcdouіvх bzvid gzgіm w jmetqou xοwcvs rtncjmev νiwsio rtqbgyqvuijmezw
    xbswu dbгtіt w wyoii Ebner-witten.de ooԁvbо bωеtuwе qmzdojme ihgdncvbmoѕ уhbgg
    xјmeѵbԁn twweyvaууvuq vоjmеqv hrtvjmecu hymcsbuxvdn
    itcgwe

    ReplyDelete