Checking Value passed by Checkbox in a jsp page ?
hi all,
in my jsp page, i've a checkbox on a page & after submitting that page to another one, i want to check whether the checkbox was clicked or not..since in my code i wanna something like this...
if checkbox is clicked
{
//task1
}
else
{//task2
}
Can anyone please help me how to go 'bout it !
[378 byte] By [
romit_k] at [2007-9-26 1:47:03]

hi,
here an ex :
in jsp1.jsp :
<form method="post" action="jsp2.jsp">
<checkbox name="test" value="test">test
</form>
in jsp2.jsp ,to know if the checkbox is checked you can do this : if (request.getParameter("test")!= null)
hope this ex will help you.
Badr.
zbadr at 2007-6-29 2:45:37 >

using
<input type="checkbox" name="myCheckBox" value="1" >
you can test with
<%
int isChecked = request.getParameter("myCheckBox")!= null ? Integer.parseInt(request.getParameter("myCheckBox")): 0;
if(isChecked ==0){
//not checked
}else{
//checked
}
%>
Hi ! romit
As the solns suggested above r correcti just wanna add another thing of ur interest ie when the checkbox is checked ,the url contains the thecked checkbox name equals "on"...i hope u understood what i meant...
ie
<input type=checkbox name="checkIt">
now in url...it will be like....
http://localhost/...../..... ..?...&check=on&.....
in case the checkbox is checked...else null value is passed....