954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

condition check of radio button

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");
            out.print("' </td>");
            out.print("<td><input type='radio' name='appStatusDescription'value='1'>Postpaid");
			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)
sunscreencert
Newbie Poster
1 post since Apr 2009
Reputation Points: 10
Solved Threads: 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
             </td>
            <td><input type='radio' name='appStatusDescription'value='1'>Postpaid
			</td></tr>
</form>			
</body>
</html>
amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: 2
Solved Threads: 1
 

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_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

hi
peter,Can you tell me
how can i access the HTML
form element
through the JSTL tag

amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: 2
Solved Threads: 1
 
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?

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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

amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: 2
Solved Threads: 1
 

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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}"        /> 
  

<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

amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: 2
Solved Threads: 1
 

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_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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

amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: 2
Solved Threads: 1
 

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You