Select only one checkbox at a time using Jquery

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this blog i will show you how to select only one checkbox at a time by using Jquery. If when we need to select only one checkbox at a time in multiple checkbox, i mean when we want to allow only one checkbox a user can check then we can do easily it by using jquery. jquery prop() through we can give attribute value checked equal to true or false.

If we have branch of checkbox like as example, and also if we want to check checkbox at time one by using jquery then we can also use this code. Now In following example use for we can to do select at a time one.

Example:

<html>
<head>
	<title>Select only one checkbox at time</title>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
	<input value="1" name="subject" class="subject-list" type="checkbox">Subject 1  
    <input value="2" name="subject" class="subject-list" type="checkbox">Subject 2  
    <input value="3" name="subject" class="subject-list" type="checkbox">Subject 3  
    <input value="4" name="subject" class="subject-list" type="checkbox">Subject 4  
    <input value="5" name="subject" class="subject-list" type="checkbox">Subject 5  
    <script type="text/javascript">
	    $('.subject-list').on('change', function() {
		    $('.subject-list').not(this).prop('checked', false);  
		});
    </script>
</body>
</html>

Read Also : How to push item to 0 index or first of $scope object in AngularJS?

Thanks for read. I hope it help you. For more you can follow us onĀ facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →