Spry

Insert the Validation Checkbox widget

  1. Locate the SpryValidationCheckbox.js file and add it to your web site. You can find the SpryValidationCheckbox.js file in the widgets/checkboxvalidation directory, located in the Spry directory that you downloaded from Adobe Labs. For more information, see Prepare your files.

    For example, create a folder called SpryAssets in the root folder of your web site, and upload the SpryValidationCheckbox.js file to it. The SpryValidationCheckbox.js file contains all of the information necessary for making the Checkbox widget interactive.

  2. Locate the SpryValidationCheckbox.css file and add it to your web site. You might choose to add it to the main directory, a SpryAssets directory, or to a CSS directory if you have one.
  3. Open the web page to add the Checkbox widget to and link the SpryValidationCheckbox.js file to the page by inserting the following script tag in the page’s head tag:
    <script src="SpryAssets/SpryValidationCheckbox.js" type="text/javascript"></script> 

    Make sure that the file path to the SpryValidationCheckbox.js file is correct. This path varies depending on where you’ve placed the file in your web site.

  4. Link the SpryValidationCheckbox.css file to your web page by inserting the following link tag in the page’s head tag:
    <link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css" /> 

    Make sure that the file path to the SpryValidationCheckbox.css file is correct. This path varies depending on where you’ve placed the file in your web site.

  5. Add checkboxes to the page and assign them names and values. You can add an unlimited number of checkboxes.
    <input type="checkbox" name="checkbox1" value="1"/>
    <input type="checkbox" name="checkbox2" value="2"/>
  6. Add a container around the checkboxes by inserting span tags around the input tags, and assigning a unique ID to the widget, as follows:
    <span id="sprycheckbox1">
    	<input type="checkbox" name="checkbox1" value="1"/>
    	<input type="checkbox" name="checkbox2" value="2"/>
    </span> 
  7. To initialize the Spry validation checkbox object, insert the following script block after the HTML code for the widget:
    <script type="text/javascript">
    	var cb1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1");
    </script> 

    The new JavaScript operator initializes the Checkbox widget object, and transforms the span tag content with the ID of sprycheckbox1 from static HTML code into an interactive checkbox object. The Spry.Widget.ValidationCheckbox method is a constructor in the Spry framework that creates checkbox objects. The information necessary to initialize the object is contained in the SpryValidationCheckbox.js JavaScript library that you linked to at the beginning of this procedure.

    Make sure that the ID of the checkbox widget’s container span tag matches the ID parameter you specified in the Spry.Widgets.ValidationCheckbox method. Make sure that the JavaScript call comes after the HTML code for the widget.

  8. Save the page.

    The complete code looks as follows:

    <head> 
    ... 
    <script src="SpryAssets/SpryValidationCheckbox.js" type="text/javascript"></script> 
    <link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css" /> 
    </head>
    <body>
    	<span id="sprycheckbox1">
    		<input type="checkbox" name="checkbox1" value="1"/>
    		<input type="checkbox" name="checkbox2" value="2"/>
    	</span>
    <script type="text/javascript">
    	var cb1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1");
    </script>
    </body>