Forums Register Login

Checking Status of a Checkbox

+Pie Number of slices to send: Send
Hi,
How can i detect whether a checkbox in selected or not thru jsp code.. as i can get the value of that thru request.getParameter("checkboxname")..
Pranit..
+Pie Number of slices to send: Send

+Pie Number of slices to send: Send
As u said i tried it,It carries null to next page i am getting the proper result.It is not resolve the above problem
<%@page language="java" %>
<html>
<head>
<title>check</title>
</head>
<%
boolean blnCheckBoxNameChecked ;
String strCheckBoxValue = request.getParameter("checkboxname");
if (strCheckBoxValue != null)
blnCheckBoxNameChecked = true;
else
blnCheckBoxNameChecked = false;

%>
<body>
<form method="post" action="cal.jsp">
<input type="checkbox" name="checkboxname" value="">CheckBox
<input type="submit" name="submit">
<%=strCheckBoxValue %>

Thanks
Shankar
+Pie Number of slices to send: Send
sorry, i don't understand what exactly the problem is.
if the user doesn't click the checkbox, the result will be null. that's expected, isn't it?
+Pie Number of slices to send: Send
if you expect to see "true" or "false" printed out, then shouldn't you be outputting blnCheckBoxNameChecked ?

If you expect the checkbox itself to return a value, then you need to supply one in its value attribute
As it stands now, a checked checkbox will return an empty string, and an unchecked one will return null, which when you output between <% %> tags, will print out as the word 'null'.

If you supply a value for the checkbox, then it will return this value when the checkbox is checked, or a null if it is unchecked.

If you don't want the word null, then you need to do something tricky like:

[This message has been edited by Mike Curwen (edited November 09, 2001).]
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 21853 times.
Similar Threads
problem with unchecking checkbox
how to put images on displaytags column header????
how to maintain the state of checkboxes across page
Jsp - Radio / Checkbox
JSP : 508 Compliant
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:05:08.