Solved

How to assign value to my checkbox if it is unchecked

Posted on 2006-11-28
6
786 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

808 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