Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  56] [ 1]  / answers: 1 / hits: 16264  / 11 Years ago, fri, september 27, 2013, 12:00:00

I'm working on jsp application and I have a form that has a checkbox, I retrieve data from my database which has a bit field named "principal", I can get the value of this field which is a boolean but I can't checked or unchecked the checkbox depending on the value of "principal".


Here's my JSP code:


<tr>
<td>Principal:</td>
<td colspan="2">
<input type="checkbox" id="a_principal" name="a_principal" value="<%=directorio.isPrincipal()%>"/>
</td>
</tr>

Javascript code:


$(function (){
if('#a_principal' == true){
$("input:checkbox").attr('checked', true);
}else{
$("input:checkbox").attr('checked', false);
}

});

More From » java

 Answers
78

try with .prop instead of .attr()



$(function (){
if($('#a_principal').val()== true){
$(input:checkbox).prop('checked',true);
}else{
$(input:checkbox).prop('checked', false);
}
});


Js Fiddle Demo


[#75374] Thursday, September 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nora

Total Points: 248
Total Questions: 111
Total Answers: 97

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
;