YUI Library Home

YUI Library Examples: Button Control: Replacing the content of a Button's Menu

Button Control: Replacing the content of a Button's Menu

This example illustrates how to replace the content of a Button's Menu on the fly.

Pizza Order Form
Pizza Type

Button's menu attribute is documented as being writeOnce — meaning that the attribute can only be set once, either via the the object literal passed to the constructor, or on an instance via the set method. However, although the menu attribute can only be set once, the Menu widget's API makes it easy to replace the content of a Menu instance on the fly. In this example, the content of the "Pizza Size" Menu is controlled by the type of pizza the user has selected.

The code used to replace the content of the "Pizza Size" Menu in this example resides in the onCheckedChange function, a listener for the checkedChange event of the two radio buttons. Each listener receives an array of MenuItem configuration properties, used to rebuild the content of the "Pizza Size" Menu, either by using the Menu's clearContent method, or by setting the Menu's itemData property.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings