• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking Status of a Checkbox

 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
rudayashanker
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!