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

if((app.getBillingModel)==0)
<html>
<head>
<script language="JavaScript">
function checkedOne(str)
{
 
   var len=document.f2.appStatusDescription.length;
  
   
 for(var i=0;i<len;i++)
{

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

} 

  
}


</script>
</head>
<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">
            <tr>
            <td>Billing Model
			<tr><td><input type='radio' name='appStatusDescription'value='0'  >Prepaid<br>
             </td>
            <td><input type='radio' name='appStatusDescription'value='1'>Postpaid<br>
			</td></tr>
</form>			
</body>
</html>

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 :)

hi
peter,Can you tell me
how can i access the

HTML 
form element

through the JSTL tag

hi
peter,Can you tell me
how can i access the

HTML 
form element

through the JSTL tag

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

hi
peter

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
so
you put also use of

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

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

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

Sessions is the answer, and before you ask about the use of sessions have look here (near the end you will find section on JSTL)

peter
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

That example is for beginners to get them started and point them in correct direction, not for hardened pros.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.