...

View Full Version : How to get checkbox values?



pashah72
01-31-2005, 09:28 AM
Hello

I have a form in which radio buttons, text field, drop down menu & check boxes are present. After entering data in form, I get values of text field, radio buttons & drop down menu thru Jsp but problem is in getting check box values since users can click multiple check boxes. Text field value can be got thru its name parameter but there are many check boxes.

Here is the code :

<body bgcolor="#ffffff">
<form method=GET action="getdata.jsp" name="try">
<table border="1">
<tr>
<td>Field1 : </td>
<td><input type="text" name="txt" value="hi"></td>
</tr>

<tr>
<td>Field2 :</td>
<td><input type="checkbox" name="c1" value="c1check">C1&nbsp;&nbsp;&nbsp;

<input type="checkbox" name="c2" value="c2check" checked>C2&nbsp;&nbsp;&nbsp;

<input type="checkbox" name="c3" value="c3check">C3&nbsp;&nbsp;&nbsp;

</td>
</tr>
</table>
</form>
</body>
</html>


JSP CODE :

//getting value of textfield
<% String Field1=request.getParameter("txt");%>
Field 1 : <%=Field1%>
<br>

//Only one checkbox value is coming.
<% String Field2=request.getParameter("c1");%>
Field 2 : <%=Field2%>

How to know which is check & get its value?

Looking forward for an early reply.

glenngv
01-31-2005, 10:56 AM
Just like radio buttons and select boxes, only selected/checked items get submitted to the server. So if you request the parameter and it returns null, it means it is not checked. If not null, then the returned value is the value of the checked item.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum