Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
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
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Struts
how do i make a radio button to be checked when a page loads up?
kay lin
Ranch Hand
Posts: 132
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Karl Beowulph
Ranch Hand
Posts: 130
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
... MyDTO myDTO = new MyDTO(); ... myDTO.setRadio("valueOne"); request.setAttribute("myBean", myDTO);
webpage.jsp
<jsp:useBean id="myBean" scope="session" class="myPackage.MyDTO"/> ... <html:radio name = "myBean" property = "radio" value = "valueOne">Value 1</html:radio> <html:radio name = "myBean" property = "radio" value = "valueTwo">Value 2</html:radio> ...
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.
Mathur Neni
Ranch Hand
Posts: 33
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I think, javascript can be one of the solution for selecting a radio button.
Marc Peabody
pie sneak
Posts: 4727
I like...
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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.
A good workman is known by his tools.
Prakash S.V.S
Greenhorn
Posts: 1
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Either through javascript or with the help of ActionForm's setter method before loading the page can do this.
--<p>Prakash S.V.S
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
how to set checked to checkbox and radio button
JSP and radio buttons passing values
jsp not reloaded in frame
setting a radio button
Radio Buttons
More...