Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value from the first checkbox which is not hidden

I need to get the value from a checkbox which is not hidden.

Here is my HTML & JQuery code

$(document).ready(function() {

  var maanu = $('.form').find('input[type=checkbox]:checked').filter(':first').val();

  alert(maanu);

});
.hide {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='form'>
  <input class="bills hide" type="checkbox" value="01" checked="checked" />
  <br />
  <input class="bills" type="checkbox" value="02" />
  <br />
  <input class="bills" type="checkbox" value="03" checked="checked" />
  <br />
  <input class="bills " type="checkbox" value="04" checked="checked" />
  <br />
  <input class="bills " type="checkbox" value="05" />
  <br />
  <input class="bills " type="checkbox" value="06" />
  <br />
  <input class="bills " type="checkbox" value="07" />
  <br />
  <input class="bills " type="checkbox" value="08" />
  <br />
</div>

DEMO

like image 700
Mo. Avatar asked Jun 18 '12 14:06

Mo.


2 Answers

Use the :visible selector:

$('input:checkbox:checked:visible:first').val();
like image 159
Anthony Grist Avatar answered Sep 29 '22 11:09

Anthony Grist


Try - http://jsfiddle.net/xgQVG/6/

$(document).ready(function(){

    var maanu = $('.form').find('input[type=checkbox]:checked:not(:hidden)').filter(':first').val();

    alert(maanu);

});
like image 30
Zoltan Toth Avatar answered Sep 29 '22 11:09

Zoltan Toth