wood burning stoves 2.0*
The moose likes JSP and the fly likes How to dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "How to dynamically "Check" the radio button based on condition" Watch "How to dynamically "Check" the radio button based on condition" New topic
Author

How to dynamically "Check" the radio button based on condition

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Hi All,

I have a group of 3 radio buttons. I want to dynamically check one of the radio button based on some condition. How do I make this work.

In my JSP I have the code like below.



Now What is happening in above code is , since I am checking for all 3 values, it's ALWAYS checking the third button no matter what is the previous selection was.
Can some one please let me know how to achieve that in above code?

thanks,
trupti
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Check for them individually and only put the checked attribute on the appropriate control.

P.S. Java code in a JSP is a discredited poor practice. You should be using the JSTL and EL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
I made below changes as per your suggestion if that is what you meant..


With this change the first time the user logs in "futures" radio button is chosen. But if I select optionsCall or put, the next time the page refreshes none
of the radio buttons are selected. The idea is when the user selects a radio button, on the page refresh it should maintain the value in session when the page gets loaded.
I can see that the servlet getting the correct value for the selected radio button but somehow in JSP it's not working.
Can you please point out mistakes in the code.

thanks
Trupti


trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
I was able to achieve this. I made some changes to my code. and it worked.
Thanks
Trupti
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

 
GeeCON Prague 2014
 
subject: How to dynamically "Check" the radio button based on condition