0

Hi friends

i am having n number check box, if i checked one check box it has to select all the similar values of the check box and the other check box should be disable.

can any one help me to solve the issue

i am having a java script for select similar values selection

<script type='text/javascript'>
(function()
{
 var allInps = document.getElementsByTagName('input'), allCb = [];
   
 for( var i in allInps )
  if( allInps[ i ].type === 'checkbox' )
  {
   allCb.push( allInps[ i ] );   
   allInps[ i ].onclick = likeMe;
  }
   
 function likeMe()
 {
  for( var i in allCb )
   if( allCb[ i ] !== this && allCb[ i ].value === this.value )
    allCb[ i ].checked = this.checked;  
 }  
   
})();
</script>
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by rpv_sen
0

I think there is a problem inside likeMe function. I think you are expecting to refer the clicked element using 'this', but it won't..! 'this' inside the function will refer to the DOM itself.
Put a parameter to function likeMe:

function likeMe(e)

Then replace 'this' with 'e.currentTarget'

Edited by niranga: n/a

0
<script type='text/javascript'>
(function()
{
var allInps = document.getElementsByTagName('input'), allCb = [];


for( var i in allInps )
if( allInps[ i ].type === 'checkbox' )
{
allCb.push( allInps[ i ] );
allInps[ i ].onclick = likeMe;
}


function likeMe()
{
for(var i in allCb )
if( allCb[ i ] !== this && allCb[ i ].id === this.id )
allCb[ i ].checked = this.checked;
else if (allCb[ i ].checked !== this.checked && allCb[ i ].id !== this.id )
{
allCb[ i ].setAttribute('disabled',true);
}
else {
allCb[ i ].removeAttribute('disabled');
}
}


})();

Edited by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.