Pre-Populating SELECT Boxes with HTC Controls

When building web based applications, I frequently have a need to pre-populate the value of SELECT controls.  I found this code some years ago on but don't remember the original author, but I certainly thank him for making several of my web-based projects considerably more user-friendly.

<attach event="oncontentready" handler="initialSelection" />

<script type="text/javascript">
// You must specify "initialValue" as a name-value pair on the combo-box
// Example: <select initialValue="TEST"></select>

// Also, the behavior of the SELECT objects must be referenced in the object's style
// Example:
BEHAVIOR: url('/includes/[this file name].htc');

function initialSelection() {
   for (var i = 0; i < this.options.length; i++) {
      if (this.options[i].value == this.initval) { 
         this.options[i].selected = true;

Skip to main content