• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

how do i make a radio button to be checked when a page loads up?

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all:
as you know, in html, if I want the radio button to be the checked when a page loads up, i'd do

<input type ="radio" name="r1" checked/>

how do i do that in struts? I don't think there is a checked field associated with
<html:radio> is there? please let me know...

thanks
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way I did it was to pass a value to the .jsp through a bean with a pre-choosen value in there.

Following are code snippets

Action.java


webpage.jsp


When the page loads, the radio which matches the value will be highlighted.

As far as having it on without a javaBean, I don't know of a way to do that.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, javascript can be one of the solution for selecting a radio button.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need any special tricks. Something like this works for prepop:

<html:radio property="gender" value="male">Male</html:radio>
<html:radio property="gender" value="female">Female</html:radio>

ActionForm needs a getter/setter for gender (as usual).

If you wanted it to default to Male at the beginning, make "male" the value of String gender in your ActionForm.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either through javascript or with the help of ActionForm's setter method before loading the page can do this.
reply
    Bookmark Topic Watch Topic
  • New Topic