Link to home
Start Free TrialLog in
Avatar of Sh_Rashed
Sh_Rashed

asked on

How to assign value to my checkbox if it is unchecked

Hi Experts,

I have table in a form and the table has many rows.

In each row I have check box its name is name = "issueItem1" .. it could be issueItem2 or 3 .. according to the row index.

When it is checked, the value = "issue<%= i %>" .. Where i is the row index , but  if the check box is unchecked it gives me null value in my Servlet

here is my tag:

<td class = "td"><input type="checkbox" name="checkIssue<%=i%>" value="issue<%=i%>"></td>

so how I can assign value to my checkbox if it is unchecked?

any idea ? .. =)
Avatar of HonorGod
HonorGod
Flag of United States of America image

 The code that you show appears to be PHP, which is code to be executed on the server.  At the time this code is executed (on the server), the checkbox can have no value.  So, I'm confused (which is nothing new).

  Can you "view source" on your browser, to see what the code looks like there?
you cannot do that. Try to use some other HTML control (two radio buttons, a select box).
Avatar of Sh_Rashed
Sh_Rashed

ASKER

I am using jsp and servlet .. I need to send the form to the Servlet .. BUT if the check box is unchecked , it sends null value

I need the value of checkbox " When it is checked" to be YES else NO..
ASKER CERTIFIED SOLUTION
Avatar of enachemc
enachemc
Flag of Afghanistan image

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
If you insist (but you really should change the logic of the jsp):

<%
String[] checks = new String[maxCheckboxes];
String checkVal = "";
for (int i=0;i<maxCheckboxes;i++) {
  checkVal=request.getParameter("checkIssue"+i);
  checks[i] = (checkVal==null || "".equals(checkVal))?"NO":"YES";
}
%>
OK I got it .. I will change it to radio buttons ..

Thanks = )