Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to achieve this. I made some changes to my code. and it worked.
Thanks
Trupti
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic