Link to home
Start Free TrialLog in
Avatar of royalcyber
royalcyber

asked on

How to make the checkbox work with the boolean variable

Hi

I have this code
<td width='15%' align = 'center'><input type="checkbox" value="<%=next_IREMCustomer.getRegistration_type()%>"></td>
registration_type is a boolean field which passes either true or false

Now what I need is that when the value is true the checkbox shows a checkmark and if it is false it doesn't show.

Any help will be greatly appreciated
Avatar of jessegivy
jessegivy
Flag of United States of America image

Here's the short if notation:

<td width='15%' align = 'center'><input type="checkbox" value="<%=next_IREMCustomer.getRegistration_type()?1:0%>"></td>

...uhh on second thought what you'll really wanna do is something more like this:

<td width='15%' align = 'center'><input type="checkbox" value="whatever ya wanna post to the server" <%if(next_IREMCustomer.getRegistration_type()){%>checked<%}%></td>

the value attribute has nothing to do with the checked state of the checkbox, it's simply the string that get's posted to the server and can be anything you want.  When you check to see if the checkbox is checked it's just by assuring that it's not null, so in most situations the value is not even really used.

Let me know if ya gots questions.

Cheers,

Jesse
Avatar of mvantuyl
mvantuyl

You could do something like this:

<td width='15%' align = 'center'><input type="checkbox" <% if (next_IREMCustomer.getRegistration_type()) out.println("CHECKED"); %>"></td>
ASKER CERTIFIED SOLUTION
Avatar of jeandp
jeandp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial