SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,791
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)

    get check radio button value with js

    I am having a brain f@rt, or maybe a code related pre-senior moment.

    I thought a radio button set had a js property, similar to selectedIndex of a dropdown list that would allow you to easily retrieve the value of a checked button.

    I know how to do this in jQuery via ":button :checked", or in js with a foreach loop to iterate through the button elements an attaching an event listener to each one. Which is fine it just seems convoluted if there was already a native way of doing this. Have I really forgotten something or am I just dreaming?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dresden_phoenix View Post
    Have I really forgotten something or am I just dreaming?
    I don't think that you've forgotten anything. It could be a useful scripting behaviour to have, but there doesn't seem to be anything built in that lets you retrieve the value of the currently selected radio button.
    Last edited by paul_wilkins; Mar 4, 2012 at 05:09.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,791
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    Thanks Paul_W. My neurons must have been tangled.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •