Solved

How to assign value to my checkbox if it is unchecked

Posted on 2006-11-28
6
784 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
Comment Utility
 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
Comment Utility
you cannot do that. Try to use some other HTML control (two radio buttons, a select box).
0
 

Author Comment

by:Sh_Rashed
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Accepted Solution

by:
enachemc earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
OK I got it .. I will change it to radio buttons ..

Thanks = )
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

743 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

19 Experts available now in Live!

Get 1:1 Help Now