• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic