Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Checking Status of a Checkbox

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic