Un/Check Javascript

hi experts,

I'm looking for JS which check and uncheck all records with single click.

[]Un/Check All     Name        UserID
   []                      abc           111
   []                      bbc           222

Thx,
PH
princehyderabadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cem TürkSenior Software EngineerCommented:
princehyderabadAuthor Commented:
The above URL script is unchecking the checked box and checking unchecked box.

What I want is simple, UnCheck all or Check all, irrespective of if few/none checkbox was previous checked or not.
HonorGodSoftware EngineerCommented:
<html>
<head>
<title></title>
<script language='JavaScript' type='text/javascript'>
  function checkIT( val )
  {
    var cbs = document.body.getElementsByTagName( 'INPUT' );
    for ( var i = 0; i < cbs.length; i++ ) {
      if ( cbs[ i ].type == 'checkbox')
        cbs[i].checked = val;
    }
  }
</script>
</head>

<body>
<input type='checkbox'></input>
<input type='checkbox'></input>
<input type='checkbox'></input>
<input type='checkbox'></input>
<input type='checkbox'></input>
<input type='button' onclick='checkIT(true)' value='Select'></input>
<input type='button' onclick='checkIT(false)' value='Reset'></input>
</body>
</html>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

bubbledragonCommented:
Hi, princehyderabad

Addition for HonorGod code,

If use one checkbox to handle another checkbox you can change to below: -

<input type='checkbox' onclick='checkIT(this.checked)'> Un/check All
princehyderabadAuthor Commented:
Bascially with one check box I want to hand other checkboxes. I like to have like push ON/OFF button.


Click chekcbox, all rest of checkbox CHECKED.

Another time click checkbox, all rest of chechbox Unchecked.
hiteshgupta1Commented:
i think,u haven't looked at the the soultion given by  bubbledragon
use following inout tak for all checkboxes
<input type='checkbox'  onclick='checkIT(this.checked)'></input>
u won't need any button then
hiteshgupta1Commented:
i've just modified the code posted by HonorGod

 <html>
<head>
<title></title>
<script language='JavaScript' type='text/javascript'>
  function checkIT( val )
  {
    var cbs = document.body.getElementsByTagName( 'INPUT' );
    for ( var i = 0; i < cbs.length; i++ ) {
      if ( cbs[ i ].type == 'checkbox')
        cbs[i].checked = val;
    }
  }
</script>
</head>

<body>
<input type='checkbox'  onclick='checkIT(this.checked)'>check/Uncheck all</input>
<BR>
<input type='checkbox'>Choice 1</input><BR>
<input type='checkbox'>choice 2</input><BR>
<input type='checkbox'>choice 3</input><BR>
<input type='checkbox'>choice 4</input><BR>

</body>
</html>
hiteshgupta1Commented:
i've just modified the code posted by HonorGod

 <html>
<head>
<title></title>
<script language='JavaScript' type='text/javascript'>
  function checkIT( val )
  {
    var cbs = document.body.getElementsByTagName( 'INPUT' );
    for ( var i = 0; i < cbs.length; i++ ) {
      if ( cbs[ i ].type == 'checkbox')
        cbs[i].checked = val;
    }
  }
</script>
</head>

<body>
<input type='checkbox'  onclick='checkIT(this.checked)'>check/Uncheck all</input>
<BR>
<input type='checkbox'>Choice 1</input><BR>
<input type='checkbox'>choice 2</input><BR>
<input type='checkbox'>choice 3</input><BR>
<input type='checkbox'>choice 4</input><BR>

</body>
</html>
princehyderabadAuthor Commented:
Yeah I think its working. let me work in Lab and get back
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.