For example, create a folder called SpryAssets in the root folder of your web site, and upload the SpryValidationSelect.js file to it. The SpryValidationSelect.js file contains all of the information necessary for making the Select widget interactive.
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
Make sure that the file path to the SpryValidationSelect.js file is correct. This path varies depending on where you’ve placed the file in your web site.
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
Make sure that the file path to the SpryValidationSelect.css file is correct. This path varies depending on where you’ve placed the file in your web site.
<select name="myselect" id="myselect"></select>
<select name="myselect" id="myselect"> <option>--Please select an item--</option> <option value="item1">Item 1</option> <option value="item2">Item 2</option> <option value="-1">Invalid Item</option> <option value="item3">Item 3</option> <option>Empty Item</option> </select>
<span id="spryselect1"> <select name="myselect" id="myselect"> <option>--Please select an item--</option> <option value="item1">Item 1</option> <option value="item2">Item 2</option> <option value="-1">Invalid Item</option> <option value="item3">Item 3</option> <option>Empty Item</option> </select> </span>
<script type="text/javascript"> var selectwidget1 = new Spry.Widget.ValidationSelect("spryselect1"); </script>
The new JavaScript operator initializes the Select widget object, and transforms the span tag content with the ID of spryselect1 from static HTML code into an interactive select object. The Spry.Widget.ValidationSelect method is a constructor in the Spry framework that creates select objects. The information necessary to initialize the object is contained in the SpryValidationSelect.js JavaScript library that you linked to at the beginning of this procedure.
Make sure that the ID of the select list’s container span tag matches the ID parameter you specified in the Spry.Widgets.ValidationSelect method. Make sure that the JavaScript call comes after the HTML code for the widget.
The complete code looks as follows:
<head> ... <script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" /> </head> <body> <span id="spryselect1"> <select name="myselect" id="myselect"> <option>--Please select an item--</option> <option value="item1">Item 1</option> <option value="item2">Item 2</option> <option value="-1">Invalid Item</option> <option value="item3">Item 3</option> <option>Empty Item</option> </select> </span> <script type="text/javascript"> var selectwidget1 = new Spry.Widget.ValidationSelect("spryselect1"); </script> </body>