Home arrow JavaScript arrow Page 2 - Creating Different Push Buttons with the Yahoo Button Control
JAVASCRIPT

Creating Different Push Buttons with the Yahoo Button Control


This is the third article in a series about the Yahoo Button Control. In it, we will discuss how to create some basic "push" buttons using the YBC, which is part of the Yahoo UI framework.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
December 04, 2007
TABLE OF CONTENTS:
  1. · Creating Different Push Buttons with the Yahoo Button Control
  2. · A review: building radio buttons and checkboxes with the Yahoo! Button Control
  3. · Extending the Use of Control Buttons
  4. · Building push buttons using predefined button control HTML

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Creating Different Push Buttons with the Yahoo Button Control - A review: building radio buttons and checkboxes with the Yahoo! Button Control
(Page 2 of 4 )

Usually, in most of my articles on web development, I like to reintroduce briefly some of the concepts that I deployed in a preceding tutorial. This article is no exception. Below I included a pair of illustrative code samples that show how to create some radio buttons and checkboxes directly with JavaScript using the neat Button Control.

Here are the mentioned code samples, so have a look at them, please:

(example of building radio buttons with the Button Control)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

  <head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1" />

  <title>Example of "radio" Yahoo Button using no existing
HTML</title>

<!-- Include core + Skin CSS files-->

<link rel="stylesheet" type="text/css"
href="build/button/assets/skins/sam/button.css">

<!-- This file is optional: Menu Stylesheet (required for
creating buttons of type "menu" and "split") -->

<link rel="stylesheet" type="text/css"
href="build/menu/assets/skins/sam/menu.css">

<!-- Include dependencies -->

<script type="text/javascript" src="build/yahoo-dom-event/yahoo-
dom-event.js"></script>

<script type="text/javascript" src="build/element/element-beta-
min.js"></script>

<!-- This file is optional: Menu and Container Core (required for
creating buttons of type "menu" and "split") -->

<script type="text/javascript"
src="build/container/container_core-min.js"></script>

<script type="text/javascript" src="build/menu/menu-
min.js"></script>

<!-- Source file -->

<script type="text/javascript" src="build/button/button-beta-
min.js"></script>

</head>

<body class="yui-skin-sam">

  <script type="text/javascript">

   var sButtonGroup1 = new YAHOO.widget.ButtonGroup({

    id: "buttongroup1",

    name: "radiofield1",

  container: "container" });

sButtonGroup1.addButtons([

 { label: "Radio1", value: "Radio1", checked: true },

 { label: "Radio2", value: "Radio2" },

 { label: "Radio3", value: "Radio3" },

 { label: "Radio4", value: "Radio4" }

]);

</script>

<div id="container"></div>

</body>

</html>

(example on building checkboxes with the Button Control)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

  <head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1" />

<title>Example of "checkbox" Yahoo Button using no existing
HTML</title>

<!-- Include core + Skin CSS files-->

<link rel="stylesheet" type="text/css"
href="build/button/assets/skins/sam/button.css">

<!-- This file is optional: Menu Stylesheet (required for
creating buttons of type "menu" and "split") -->

<link rel="stylesheet" type="text/css"
href="build/menu/assets/skins/sam/menu.css">

<!-- Include dependencies -->

<script type="text/javascript" src="build/yahoo-dom-event/yahoo-
dom-event.js"></script>

<script type="text/javascript" src="build/element/element-beta-
min.js"></script>

<!-- This file is optional: Menu and Container Core (required for
creating buttons of type "menu" and "split") -->

<script type="text/javascript"
src="build/container/container_core-min.js"></script>

<script type="text/javascript" src="build/menu/menu-
min.js"></script>

<!-- Source file -->

<script type="text/javascript" src="build/button/button-beta-
min.js"></script>

</head>

 <body class="yui-skin-sam">

  <script type="text/javascript">

    var sCheckButton1 = new YAHOO.widget.Button({

     type: "checkbox",

     label: "CheckBox1",

     id: "checkbutton1",

     name: "checkboxfield1",

     value: "1",

    container: "container",

     checked: true });

  var sCheckButton2 = new YAHOO.widget.Button({

   type: "checkbox",

    label: "CheckBox2",

    id: "checkbutton2",

    name: "checkboxfield2",

    value: "2",

   container: "container",

    checked: true });

 var sCheckButton3 = new YAHOO.widget.Button({

   type: "checkbox",

    label: "CheckBox3",

    id: "checkbutton3",

    name: "checkboxfield3",

    value: "3",

   container: "container",

    checked: true });

</script>

<div id="container"></div>

</body>

</html>

As you can see from the two previous code samples, building a few basic radio buttons and checkboxes using the Yahoo! Button Control is indeed a straightforward process that can be tackled by any web developer with any intermediate experience on their shoulders.

The above practical examples demonstrate the complete procedure for creating the mentioned radio buttons and checkboxes directly with JavaScript (that is, no existing <input> tags are required), via the instantiation of the already familiar “YAHOO.widget.Button” class with the proper initialization parameters.

Now, speaking more specifically, the first example is rather special, since it shows how to create four radio buttons by using the “Yahoo.widget.ButtonGroup” class, which comes bundled with the Yahoo UI library. The second case implements a more conventional approach; it demonstrates how to build some simple checkboxes by utilizing the previously mentioned “YAHOO.widget.Button” class.

True to form, both cases are actually very simple to grasp, so I believe that you shouldn’t have any major problems understanding how they work.

So far, so good. At this time you hopefully learned how to create radio buttons and checkboxes via the utilization of the Button Control, which comes packaged with the Yahoo UI framework. So, the next step to take will consist of teaching you how to use this widget to build “push” elements by using different approaches.

As you may guess, this topic will be properly covered in the upcoming section, thus click on the link below and keep reading.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials