How to select only one checkbox at a time in javascript example?

Today, We want to share with you only one checkbox selected at a time in javascript.In this post we will show you uncheck other checkboxes on selection of one checkbox javascript, hear for allow only one checkbox to be checked using javascript we will give you demo and example for implement.In this post, we will learn about Only one checkbox can be checked with an example.

how to select one checkbox from multiple checkboxes in javascript?

In following example use for you to do select at a time one.

Also Read This πŸ‘‰   jQuery Image slider with Next Button

Example 1: index.html

<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="shopitem" class="shopitem-list" type="checkbox">Laptop 
    <input value="2" name="shopitem" class="shopitem-list" type="checkbox">Mobile  
    <input value="3" name="shopitem" class="shopitem-list" type="checkbox">Iphone  
    <input value="4" name="shopitem" class="shopitem-list" type="checkbox">Computer  
    <input value="5" name="shopitem" class="shopitem-list" type="checkbox">LCD  
    <script type="text/javascript">
	    $('.shopitem-list').on('change', function() {
		    $('.shopitem-list').not(this).prop('checked', false);  
		});
    </script>
</body>
</html>

Using JavaScript

HTML Code

<input type="checkbox" id="1" value="laptop" onclick="getSelectItemThat(this.id)" /> Laptop 1
<input type="checkbox" id="2" value="mobile" onclick="getSelectItemThat(this.id)" /> Mobile 2
<input type="checkbox" id="3" value="computer" onclick="getSelectItemThat(this.id)" /> Computer 3
<input type="checkbox" id="4" value="lcd" onclick="getSelectItemThat(this.id)" /> LCD 4

Free Live Chat for Any Issue

JavaScript Code

function getSelectItemThat(id) {
    for (var i = 1;i <= 4; i++)
    {
        document.getElementById(i).checked = false;
    }
    document.getElementById(id).checked = true;
}

I hope you get an idea about how to select one checkbox from multiple checkboxes in javascript?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.