Solved

How to assign value to my checkbox if it is unchecked

Posted on 2006-11-28
6
788 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

685 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