Introduction:
Here I will explain how to get multiple checked
checkbox value in jQuery or jQuery
get multiple checked values from checkbox.
Description:
In previous articles I explained jQuery Price range slider examples, jQuery setInterval function example, jQuery change page title dynamically, jQuery image slideshow with semi transparent caption example,
jQuery Dropdown menu with css and many articles relating to
JQuery,
JavaScript, asp.net,
code snippets. Now I will explain how to get multiple
checked checkbox value in jQuery.
To get multiple selected checkbox values in jQuery
we need to write the code like as shown below
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function()
{
$('#btnSubmit').click(function() {
var slvals = []
$('input:checkbox[name=chkcountry]:checked').each(function() {
slvals.push($(this).val())
})
alert('Selected
Checkbox values are: ' + slvals)
})
});
</script>
</head>
<body>
<b>Sample checkbox inputs :</b>
<input type="checkbox" name="chkcountry" id="chkindia" value="India" />India
<input type="checkbox" name="chkcountry" id="chkusa" value="USA" />USA
<input type="checkbox" name="chkcountry" id="chkAustralia" value="Australia" />Australia
<input type="checkbox" name="chkcountry" id="chkMalaysia" value="Malaysia" />Malaysia
<button id="btnSubmit">Get
Selected Values</button>
</body>
</html>
|
Demo
Sample checkbox inputs :
India
USA
Australia
Malaysia
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
4 comments :
how we are getting comma seperated by each checked value
Hi Suresh,Nice Work.
Theosoft
is there any way to access this values from backend
or
run this script from backend...
please reply as soon as possible..
email is: dharmik6610@gmail.com
it worked thanks
Note: Only a member of this blog may post a comment.