Solved

How to assign value to my checkbox if it is unchecked

Posted on 2006-11-28
6
785 Views
Last Modified: 2008-02-01
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 ? .. =)
0
Comment
Question by:Sh_Rashed
6 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 18028375
 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?
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18028405
you cannot do that. Try to use some other HTML control (two radio buttons, a select box).
0
 

Author Comment

by:Sh_Rashed
ID: 18028513
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..
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Accepted Solution

by:
enachemc earned 250 total points
ID: 18028549
I understoot that. But the behaviour of the checkbox is to not send anything back to the server if it is not checked. If you realy want to send yes or no, use two radio buttons or a select box with the two values.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 18028605
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";
}
%>
0
 

Author Comment

by:Sh_Rashed
ID: 18028669
OK I got it .. I will change it to radio buttons ..

Thanks = )
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now