Htlm as follows :
<table class="tablesorter">
<g:each in="${vehicleInstanceList}" status="i" var="vehicleInstance">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}" id ="rows">
<td >
<g:checkBox id = "isActive_${i}" class="isActive" name="isActive" value="${vehicleInstance?.isActive}" />
<input type="hidden" value="${vehicleInstance?.id}" name="vehicleId" id="isActive_${i}_" />
</td>
</tr>
and Jquery :
$(".isActive").click(function() {
var checkBox_id = $(this).attr("id"); // getting the id of checkbox
var isActive = // get the value of checkbox
var veh开发者_开发知识库icleId = // get the value of hidden input element
});
i have to get the value of checkbox and hidden input element how can i do it? isActive is a boolean type and i want answer in terms of true/false , if checked true else false
var isActive = $('#'+checkBox).is(':checked'); i have tried to get value of checkbox but it always gives output as false
$("#elementID").val();
will get the value of the selected element. For the checkbox, you can use $(this)
as your selector, as you did for getting the id
.
Try this.
var isActive = $(this).is(":checked");
var vehicleId = $(this).closest("td").find(":hidden").val();
Please try this:
- Get the parent of the check box who is actually the parent for that hidden also.
- Find the hidden field in the parent.
Simple... !
sample snippet
$('.isActive').click(function(){
var isActive = $(this).is(':checked');
console.log(isActive);
var _vehicle = $(this).parent().find('input[type=hidden]').val();
console.log(_vehicle);
});
Fiddle link for Assistance : http://jsfiddle.net/baELR/2/
精彩评论