• Post Reply Bookmark Topic Watch Topic
  • New Topic

Selecting all the checkbox by hiting the submit button in jsp  RSS feed

 
rudayashanker
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*I all ready tryed in client side javascript it works fine.

*I just working on server side jsp
When the first time page loaded all the check box are checked .I did't hit the submit button .
can any one help me
I making simple mistake some where...
code is below
----------------------------
<%@ page language ="java" %>
<html>
<head>
</head>
<body>
<%!
//String ajazz = null;
//String apop = null;
//String arock = null;
//String submit != null;
%>
<%
String ajazz = request.getParameter("jazz");
String apop = request.getParameter("pop");
String arock = request.getParameter("rock");
//String submit = (request.getParameter("submit") != null ? request.getParameter("submit") : "");
%>
<body>
<form method="get" action="check.jsp">
<input type="checkbox" name="jazz" value="jazz"<%=(ajazz ==null)?"Checked" : ""%>>Jazz<br>
<input type="checkbox" name="pop" value="pop"<%=(apop ==null)?"Checked" :""%>>POP<br>
<input type="checkbox" name="rock" value="rock"<%=(arock ==null)?"Checked" :""%>>ROCK<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Thanks
Shankar
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason for this, is that request.getParameter will return an empty String .equals("") if there is no value, so it will never be null...
James
 
ziqiang wu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page language ="java" %>
<html>
<head>
</head>
<body>
<%!
String ajazz = "";
String apop = "";
String arock = "";
//String submit != null;
%>
<%
if(session.getValue("first_time")==null)
{
ajazz ="**";
apop = "**";
arock = "**";
session.setAttribute("first_time", "**");
}
else
{
ajazz = request.getParameter("jazz");
apop = request.getParameter("pop");
arock = request.getParameter("rock");
}
//String submit = (request.getParameter("submit") != null ? request.getParameter("submit") : "");
%>
<body>
<form method="get" action="check.jsp">
<input type="checkbox" name="jazz" value="jazz"<%=(ajazz ==null)?"Checked" : ""%>>Jazz<br>
<input type="checkbox" name="pop" value="pop"<%=(apop ==null)?"Checked" :""%>>POP<br>
<input type="checkbox" name="rock" value="rock"<%=(arock ==null)?"Checked" :""%>>ROCK<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
hope it work.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!