[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

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
0
royalcyber
Asked:
royalcyber
1 Solution
 
jessegivyCommented:
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
0
 
mvantuylCommented:
You could do something like this:

<td width='15%' align = 'center'><input type="checkbox" <% if (next_IREMCustomer.getRegistration_type()) out.println("CHECKED"); %>"></td>
0
 
jeandpCommented:
try this:

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

This will add the string "checked" to the input field if registration_type is true and then the browser will put a check in the checkbox.

the html output will then look like this: <input type="checkbox" value="true" checked>
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now