SUBSCRIBE VIA RSS


Subscribe to our feed

Status Updates

  • First iPhone app nearly complete! I've been waiting for 3 weeks for Apple to finish "conducting company identity verification."
    1 day ago
  • Rainy day! Staying indoors. Creating computerized players in a simulation game that models cooperation in the work place.
    73 days ago
  • Up at 8AM, with a hot cup of coffee brought back from Cafe Lola in Ann Arbor. Will I succeed in putting in 8 billable hours in one day?
    99 days ago
  • full scale irish band outside my window playing the pipes for the past 20 minutes. pretty fun.
    107 days ago
  • listening to Kristin on Maxim Radio!
    113 days ago
  • back from an amazing meal at ouest with even more amazing company.
    114 days ago
  • wondering how so many online tshirt companies stay in business--ones that sell shirts with funny messages, i never see them in real life
    120 days ago

Topics

TWITTER

The old fashioned way

RECENT TUNES

June 5, 2008 – 12:50pm Get value of radio button group using prototype

If you want to get the value of the selected element of a radio group, prototype makes this easy. There is more than one way to do it. I’ll update this post as better methods surface. Check out code after the jump.

$$('input:checked[type="radio"][name="my_radio_group"]').pluck('value');

What this does is use css selectors to pull out an input element with the attribute “checked” of type “radio” and with the name”my_radio_group”. The $$ function returns an array, although in this case it is only one element long. “pluck” returns the given attribute (in our case we want the value attribute) for the elements in the array.

Posted in  Web Development   |     |  delicious  Digg

6 Responses to “Get value of radio button group using prototype”

  1. It works great. Thanks a lot for sharing :)

    By Hieu Le on Jul 3, 2008

  2. Works like a charm! Thanks!

    By Leon on Jul 31, 2008

  3. Works a treat, thanks heaps!

    By Nik Wakelin on Sep 30, 2008

  4. Very elegant! I laughed out loud when I read it. I love how you can do this kind of stuff with Prototype.

    By Grant on Oct 18, 2008

  5. Very elegant, thank you! As a Prototype rookie, though, I’m wondering… don’t you need to have [0] at the end of that line? pluck() seems to return an array, and you want the scalar value for the chosen value. It seems to work just fine as-is, so maybe I don’t have a thorough understanding of how JS arrays work…

    By Jeff Garbers on Nov 18, 2008

1 Trackback(s)

  1. Mar 4, 2009: Obtener el valor de la selección de un grupo de radiobuttons con Prototype - 6th Edition

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word