views:

339

answers:

2

i'm using Mvc checkbox.

by default the rendering a checkbox like below.

<input id="test" type="checkbox" value="true" name="test"/>
<input type="hidden" value="false" name="test"/>

so whn itry to access

$("#tets").val() returns true, but defaultly it is false.

Any idea how to access checkbox using jquery

A: 

I think you'd have to do it like this:

var value = $('#test:checked').length ? $('#test').val() : $('input[name=test]').eq(1).val();

Or written a different way

var value = $('input[name=test]').eq(!$('#test:checked').length).val();
Greg
+3  A: 
var value = $("#tets").is(":checked");
takepara