943,670 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 11083
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 28th, 2009
0

condition check of radio button

Expand Post »
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.

JSP Syntax (Toggle Plain Text)
  1. out.println("<tr><td>Billing Model");
  2. out.print("<tr><td><input type='radio' name='appStatusDescription'value='0' >Prepaid<br>");
  3. out.print("' </td>");
  4. out.print("<td><input type='radio' name='appStatusDescription'value='1'>Postpaid<br>");
  5. 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
JSP Syntax (Toggle Plain Text)
  1. if((app.getBillingModel)==0)
Last edited by peter_budo; Apr 28th, 2009 at 5:49 pm. Reason: Correcting code tags, please use [code][/code]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunscreencert is offline Offline
1 posts
since Apr 2009
Apr 29th, 2009
0

Re: condition check of radio button

JSP Syntax (Toggle Plain Text)
  1.  
  2.  
  3. <html>
  4. <head>
  5. <script language="JavaScript">
  6. function checkedOne(str)
  7. {
  8.  
  9. var len=document.f2.appStatusDescription.length;
  10.  
  11.  
  12. for(var i=0;i<len;i++)
  13. {
  14.  
  15. if(str==1)
  16. {
  17.  
  18. if( document.f2.appStatusDescription[i].value==0)
  19. {
  20. alert("This code is going to the checked ,Prepaid radio button");
  21. document.f2.appStatusDescription[i].checked=true;
  22.  
  23. }
  24. }
  25.  
  26. }
  27.  
  28.  
  29. }
  30.  
  31.  
  32. </script>
  33. </head>
  34. <body onLoad="checkedOne(1)">
  35. <%--
  36. here in checkedOne function you have to pass the parameter which is get from the server end
  37. means dynamic value , from that value you make the condition around the radio button
  38. --%>
  39. <form action="go" name="f2">
  40. <tr>
  41. <td>Billing Model
  42. <tr><td><input type='radio' name='appStatusDescription'value='0' >Prepaid<br>
  43. </td>
  44. <td><input type='radio' name='appStatusDescription'value='1'>Postpaid<br>
  45. </td></tr>
  46. </form>
  47. </body>
  48. </html>
Last edited by amarjeetsingh; Apr 29th, 2009 at 2:38 am.
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
Apr 29th, 2009
-1

Re: condition check of radio button

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
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Apr 30th, 2009
0

Re: condition check of radio button

hi
peter,Can you tell me
how can i access the
HTML 
form element
through the JSTL tag
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
Apr 30th, 2009
-1

Re: condition check of radio button

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?
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Apr 30th, 2009
0

Re: condition check of radio button

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
Last edited by amarjeetsingh; Apr 30th, 2009 at 6:09 am.
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
Apr 30th, 2009
-1

Re: condition check of radio button

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
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Apr 30th, 2009
0

Re: condition check of radio button

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

JSP Syntax (Toggle Plain Text)
  1. <c:set var="s" value="${param.name}" />
  2. <c:out value="${s}" />
  3. <br>
  4.  
  5. <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
Reputation Points: 2
Solved Threads: 1
Newbie Poster
amarjeetsingh is offline Offline
21 posts
since Feb 2009
Apr 30th, 2009
-1

Re: condition check of radio button

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)
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Apr 30th, 2009
0

Re: condition check of radio button

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

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: How can i know which submit was clicked
Next Thread in JSP Forum Timeline: javamail





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC