File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes finding the value of a radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "finding the value of a radio button" Watch "finding the value of a radio button" New topic
Author

finding the value of a radio button

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303


In a jsp page, I have the following code:

The automationList has the following values: TYPE1, TYPE2,TYPE3. I want to check the value of the radio button clicked. If if is TYPE1, then i want to do something. Would anybody have any ideas?

I tried the following, but didnt work.



SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The approach you've shown us looks like you took JavaScript code that worked with a dropdown box and tried to make it work with a radio button group. The two controls are very different, so this approach isn't going to work. Here's how I'd approach it:
  • Get a nodelist containing all the radio buttons. You can do this with the document.getElementsByName() function
  • Iterate through the node list.
  • You can tell if a radio button is checked or not using its checked property
  • You can tell which radio button you're currently looking at by examining its value property
  • This should give you enough to get you started in the right direction.
    [ June 05, 2007: Message edited by: Merrill Higginson ]

    Merrill
    Consultant, Sima Solutions
    JayaSiji Gopal
    Ranch Hand

    Joined: Sep 27, 2004
    Posts: 303
    As advised, I tried the following code:



    This does not work. Any help?
    Merrill Higginson
    Ranch Hand

    Joined: Feb 15, 2005
    Posts: 4864
    Change

    to

    Also remember that it's the list variable that you should be iterating over, not automationList. The automationList variable is a Java variable, not a JavaScript variable, so it's of no use here. Each button can be represented by list[i] in your code. Example:

    [ June 06, 2007: Message edited by: Merrill Higginson ]
    JayaSiji Gopal
    Ranch Hand

    Joined: Sep 27, 2004
    Posts: 303
    I could resolve the problem. Thank you.

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: finding the value of a radio button