condition check of radio button

Reply

Join Date: Apr 2009
Posts: 1
Reputation: sunscreencert is an unknown quantity at this point 
Solved Threads: 0
sunscreencert sunscreencert is offline Offline
Newbie Poster

condition check of radio button

 
0
  #1
Apr 28th, 2009
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.

  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
  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]
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: condition check of radio button

 
0
  #2
Apr 29th, 2009
  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,257
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: condition check of radio button

 
-1
  #3
Apr 29th, 2009
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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: condition check of radio button

 
0
  #4
Apr 30th, 2009
hi
peter,Can you tell me
how can i access the
HTML 
form element
through the JSTL tag
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,257
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: condition check of radio button

 
-1
  #5
Apr 30th, 2009
Originally Posted by amarjeetsingh View Post
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?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: condition check of radio button

 
0
  #6
Apr 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,257
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: condition check of radio button

 
-1
  #7
Apr 30th, 2009
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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: condition check of radio button

 
0
  #8
Apr 30th, 2009
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

  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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,257
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: condition check of radio button

 
-1
  #9
Apr 30th, 2009
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)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: condition check of radio button

 
0
  #10
Apr 30th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JSP Forum
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC