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>

Recommended Answers

All 2 Replies

Member Avatar for stbuchok

Lines 2, 3 and 20 aren't needed.

To disable a checkbox, checkbox.disabled = true; (where checkbox is the element you want to disable)

In your likeMe function, add an else statement that disables the checkbox if they aren't similar.


I think that should work. Let me know.

Hi

Thanks for your reply

i have solved my issue

Here the java script code what i have used

<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');
   }
 }
   
})();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.