i have two radio boxes in a jsp using html and i want to make one checked based on a condition. I can do that in php but i don't know how to do that using jsp. Can anyone help me.

out.println("<tr><td>Billing Model");
			out.print("<tr><td><input type='radio' name='appStatusDescription'value='0'  >Prepaid<br>");
            out.print("' </td>");
            out.print("<td><input type='radio' name='appStatusDescription'value='1'>Postpaid<br>");
			out.print("' </td></tr>");

These are the two radio buttons and based on the return value of this i want either one of them checked

9 Years
Discussion Span
Last Post by peter_budo
<script language="JavaScript">
function checkedOne(str)
   var len=document.f2.appStatusDescription.length;
 for(var i=0;i<len;i++)

	if( document.f2.appStatusDescription[i].value==0)
	    alert("This code is going to the checked ,Prepaid radio button");



<body onLoad="checkedOne(1)">
     here in checkedOne function you have to pass the parameter which is get from the server end
	 means dynamic value  , from that value you make the condition around the radio button
<form action="go" name="f2">
            <td>Billing Model
			<tr><td><input type='radio' name='appStatusDescription'value='0'  >Prepaid<br>
            <td><input type='radio' name='appStatusDescription'value='1'>Postpaid<br>

JavaScript is one option, but I would suggest to look into JSTL. That way if you need to set radio buttons as servlet require you have far easier quest :)


peter,Can you tell me
how can i access the

form element

through the JSTL tag

Would you mind explain what you are about as your original question does not really make sense?



i am talking about html form elements
like radio button,checkboxes,textbox

in a jsp page how can you access them

through jstl tags

as you mentioned in your previous answere

JavaScript is one option, but I would suggest to look into JSTL. That way if you need to set radio buttons as servlet require you have far easier quest

if you have answere to that question
then you should give the answere


Could be simple like this

<input type='radio' name='<c:out value="${param.name}"/>' value='1' checked='<c:out value="${param.checked}"/>' />

Where the values can be set by servlet, passed in session, retried by JSTL tags for session manipulation and then set in appropriated places

PS: sunscreencert, input tag have to be closed by "/" according to HTML4.0.1, see w3schools


but the original question was that
want to make one checked radio,
based on a condition

there are 2 radio button

when the jsp load from the server end

1 radio is checked on conditionally
how can i put the condition
on the jsp load
you put also use of

<c:set         var="s"   value="${param.name}"    /> 
<c:out value="${s}"        /> 

<c:if    test="${s    eq     'value of radio button'  }">

around radio buttons
now Suppose you have 10 radio buttons
which is checked on conditionally
then how many condition put in jsp page


this is the small application for school boys,
there is so many drawbacks
in your application

have you make any connection pool
in your tutorial

do n't ask what is connection pool
have you gave the ideas to the users
what will happen 1000 users connect your
small application

by the way in session
you should set minimum attributes
because due to this your site response can be slow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.