Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finding the value of a radio button

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    JayaSiji Gopal
    Ranch Hand
    Posts: 303
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    As advised, I tried the following code:



    This does not work. Any help?
     
    Merrill Higginson
    Ranch Hand
    Posts: 4864
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 303
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I could resolve the problem. Thank you.

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic