954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to select similar check box

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>
rpv_sen
Junior Poster
178 posts since Mar 2011
Reputation Points: 18
Solved Threads: 16
 

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'

niranga
Junior Poster
163 posts since Apr 2010
Reputation Points: 21
Solved Threads: 21
 

You'd be better off posting this to the js forum. Why is it PHP?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
rpv_sen
Junior Poster
178 posts since Mar 2011
Reputation Points: 18
Solved Threads: 16
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: