I have 50 checkboxes in a page, say this page is used by a doctor to manage his patients data, So some checkboxes can be checked, some can be unchecked. I have a database table and separate columns for each this 50 checkboxes, with unchecked value 0 and checked value 1.
and in my display page , I have two ideas to make this checkboxes checked/unchecked, but both look crappy.
1.
<% if(fieldOneChecked==1){%>
<input type="checkbox" value='' name="fieldOne" checked="checked"/>
<% }else{%>
<input type="checkbox" name="fieldOne" value=''/>
<% }%>
2
<%
String foo=""
if(fieldOneChecked==1){String foo="checked=\"checked\"";}
%>
<input type="checkbox" name="fieldOne" value='' <%=foo%>/>
I have to repeat the same for 50 checkboxes.
Is there any better and easier way? Either in jsp or php, a better logic is what I want. :)
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire