4

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

R3tep
  • 12,512
  • 10
  • 48
  • 75
Shreenivas
  • 155
  • 2
  • 6
  • 19

2 Answers2

4

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


EDIT

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>>
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
-2

update Radio Button in jsp:- Code:- >Male

>Female

Umesh
  • 1