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:
0
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.
0
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>
0

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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
0
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.
0
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
0
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>
0
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>
0
princehyderabadAuthor Commented:
Yeah I think its working. let me work in Lab and get back
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.