Reputation: 155
How to retrieve radio button values with checked state in jsp ? while updating radio button from data base.
Male <input type="radio" name="R1" value="<%=rs.getString("gender")%>">
Female <input type="radio" name="R1" value="<%=rs.getString("gender")%>">
If in database its female it should be in checked state female radio button else male radio button its not checking the value for none
Upvotes: 4
Views: 12916
Reputation: 46841
Try to use JSTL & EL instead of Scriplet elements. For database access use JSTL SQL Tag library or it's better to move the database code in the Servlet.
Try with the CSS Input Radio checked Property
Sample code:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="gender" value="female"/>
Male <input type="radio" name="R1"
value="Male" <c:if test="${gender=='male'}">checked</c:if>>
Female <input type="radio" name="R1"
value="Female" <c:if test="${gender=='female'}">checked</c:if>>
Have a look at the similar post
For check box values single value its show properly but when it multiple values showing nothing.
check the string using contains method.
sample code:
<c:set var="medium" value="Hindi Kannada" />
English
<input type="checkbox" name="C1"
<c:if test="${medium.contains('English')}">checked</c:if>>
Kannada
<input type="checkbox" name="C1"
<c:if test="${medium.contains('Kannada')}">checked</c:if>>
Hindi
<input type="checkbox" name="C1"
<c:if test="${medium.contains('Kannada')}">checked</c:if>>
Upvotes: 4