How can I get the value of checkboxes which are selected using jquery? My html code is as follows:
Try getPrameterValues()
for getting values from multiple checkboxes.
You may try;
$('#save_value').click(function(){
var final = '';
$('.ads_Checkbox:checked').each(function(){
var values = $(this).val();
final += values;
});
alert(final);
});
This will return all checkbox values in a single instance.
Here is a working Live Demo.
To get an array of values from multiple checked checkboxes, use jQuery map/get functions:
$('input[type=checkbox]:checked').map(function(_, el) {
return $(el).val();
}).get();
This will return array with checked values, like this one: ['1', '2']
Here is working example on jsfiddle: http://jsfiddle.net/7PV2e/
try this one.. (guys I am a new bee.. so if I wrong then I am really sorry. But I found a solution by this way.)
var suggestion = [];
$('#health_condition_name:checked').each(function (j, ob) {
var odata = {
health_condition_name: $(ob).val()
};
health.push(odata);
});
$(document).ready(function(){
$(".chk").click(function(){
var d = $("input[name=test]"); if(d.is(":checked")){
//
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" name="test"> `test1`
<input type="checkbox" name="test"> `test2`
<input type="checkbox" name="test"> `test3`
<input type="button" value="check" class='chk'/>
Try this
<input name="selector[]" id="ad_Checkbox1" class="ads_Checkbox" type="checkbox" value="1" />
<input name="selector[]" id="ad_Checkbox2" class="ads_Checkbox" type="checkbox" value="2" />
<input name="selector[]" id="ad_Checkbox3" class="ads_Checkbox" type="checkbox" value="3" />
<input name="selector[]" id="ad_Checkbox4" class="ads_Checkbox" type="checkbox" value="4" />
<input type="button" id="save_value" name="save_value" value="Save" />
function
$(function(){
$('#save_value').click(function(){
var val = [];
$(':checkbox:checked').each(function(i){
val[i] = $(this).val();
});
});
});