How to access the value of a radio button that is checked using YUI?
Asked Answered
S

2

12

i have following radio button structure ...

<div id="test">
  <input name="test1" value="a" type="radio">
  <input name="test1" value="b" type="radio">
  <input name="test1" value="c" type="radio">
</div>

how would i go about retrieving the value of any checked radio button?

i have checked the YUI documentation an there is not really any good example.

I would also like to know how to get the element by input name in YUI?

Selffertilization answered 7/12, 2010 at 11:14 Comment(0)
F
15

In YUI 3:

var value = Y.one("#test input[name=test1]:checked").get("value");

In YUI 2:

// the null, null, null, true is optional, but returns only the first match
var input = YAHOO.util.Dom.getElementsBy(function (el) {
                return (el.name === 'test1' && el.checked);
            }, 'input', 'test', null, null, null, true);

var value = input.value;
Flooring answered 8/12, 2010 at 7:10 Comment(2)
Luke, you are my hero of the day! THANK YOU SO MUCH!!!! I hate YUI 2, I am so used to jquery, and YUI 3 looks like it has adopted a lot of things from there, but unfortunatly I have to use YUI 2 ...Selffertilization
@Flooring Just looking at this answer. I am a beginner so excuse me if I'm mistaken, but doesn't the getElementsBy() method have 6 parameters instead of 7? developer.yahoo.com/yui/docs/…Moira
F
0

If you have a reference to your ButtonGroup, you can do like this (in YUI 2):

var buttonGroup = new YAHOO.widget.ButtonGroup("test"); 
var button = buttonGroup.get("checkedButton");
var value = button.get('label');
Full answered 5/2, 2014 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.