-2

I am trying to set radio button checked by using follwing code

<td><%if ((retrieveId != 0) && (retrieveId == agency.getId())) {%>
  <input type="radio" id="agencyradio" name="agencyradio" checked="checked">
  <%} else {%>
  <input type="radio" id="agencyradio" name="agencyradio" >
    <%}%></td>

But it is not working.This is one of column of table.Please help me.

Thanks.

user100
  • 69
  • 4
  • 15

3 Answers3

0

The ID must be unique So change your id

try Below code

<td><%if ((retrieveId != 0) && (retrieveId == agency.getId())) {%>
    <input type="radio" id="agencyradio" name="agencyradio" checked>
<%} else {%>
    <input type="radio" id="agencyradio_one" name="agencyradio" >
 <%}%></td>
Lawrance
  • 975
  • 3
  • 9
  • 17
0

try this..

<td><%if ((retrieveId != 0) && (retrieveId == agency.getId())) {%>
  <input type="radio" id="agencyradio" name="agencyradio" checked>
  <%} else {%>
  <input type="radio" id="agencyradio" name="agencyradio" >
    <%}%></td>
Ajit Singh
  • 2,436
  • 23
  • 27
-1

Use EL language. Avoid scriplets in JSP

 <input type="radio" id="agencyradio" name="agencyradio" ${retrieveId ne 0 && retrieveId eq agency.id?'checked=\"checked\"':''}">

You should have agency in any of this scope page/request/session/application

Shoaib Chikate
  • 8,665
  • 12
  • 47
  • 70