• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I think, javascript can be one of the solution for selecting a radio button.
 
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Either through javascript or with the help of ActionForm's setter method before loading the page can do this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!