tags:

views:

1027

answers:

1

In YUI 3 I have a node that is my select box:

Y.get('#regionSelect');

How do I get the <option> values that are currently selected (even if there are more than one?) Also, is there a tutorial out there that tells me explicitly how to do this (I don't want to serialize a whole form)?

+2  A: 

Once you have the selector, you can chain get and each

Y.get("#regionSelect").get("options").each( function() {
   // this = option from the select
   var selected = this.get('selected');
   var value  = this.get('value');
   var text = this.get('text');
   // apply secret sauce here
});

I've just been using the demos/examples on http://developer.yahoo.com/yui/3/ to figure things out.

seth
Thanks! Where does it say how to get attributes?
Jasie
You are welcome.Any JavaScript tutorial about the DOM should have the attribs for the select and option objects (as well as all the others). Those aren't YUI specific but part of the DOM. For instance: http://www.w3schools.com/htmldom/dom_obj_select.asp
seth
The 'selected' and 'text' are actually selectors, not attributes. Left that out....
seth