Ajax Bestiary: A Javascript Field Guide
 
Ajax Bestiary: A Javascript Field Guide
 
 

Building a Dynamic Form with YUI

Posted by Don Albrecht

YUI provides for the creation of forms dynamically without the need for pre-existing markup through the Button object.

Despite its name, the button is a rich widget that supports the creation of:

  • Push Buttons
  • Link Buttons
  • Submit Buttons
  • Reset Button
  • Checkboxes
  • Radios
  • Menus
  • Split button (hybrid button menus)

Today we are exploring the creation of buttons dynamically from javascript.   Creation itself is simple. 

The syntax is:

 var oButton = new YAHOO.widget.Button({ id: "mybuttonid", type: "button", label: "My Button", container: "someelement" });

 

Where:

  • id = the id of the element to be created
  • type = the type of button (push, link, submit, reset, checkbox, radio, menu or split)
  • label = the visual label to display
  • container = the element in which to append the button.

Id and type are optional, Defaulting to a randomly created ID & "button" respectively.


1 Comment