• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

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
0
princehyderabad
Asked:
princehyderabad
2 Solutions
 
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
 
HonorGodCommented:
<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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now