Please see my html code:
<form action="#" class="check_opt" id="ckPrice">
<p><input class="niceCheck" type="checkbox" name="" value="0-49">3 millions - 10 millions (21)</p>
<p><input class="niceCheck" type="checkbox" name="" value="50-99"> >10 millions - 15 millions (7)</p>
<p><input class="niceCheck" type="checkbox" name="" value="100">15 millions and above (15)</p>
</form>
And jQuery code:
<script type="text/javascript">
$(document).ready(function() {
$('#ckPrice :checkbox').click(function() {
var price = 'abc';
$(".niceCheck").each(function() {
if ($(".niceCheck").is(":checked")) {
price += $(".niceCheck").value();
}
});
alert(price);
});
});
</script>
The alert function in bottom jQuery code only returns 'abc'. How should I do this?
inputelements shouldn't be wrapped inpelements. Uselabelinstead. Equally your+=is going to give an odd result with the values "0-49", "50-99" and "100" - selecting all 3 will give you "0-4950-99100".