3.2.0

Combo Box example

After seeing lots of questions and few answers, I thought I'd post an example of the code I put together:

// define a combo that works similar to the HTML Dropdown selector

// create combo
var objCombo = new AW.UI.Combo;

objCombo.setId ('objCombo');

// arrays for Text and Values if using AJAX
// var comboValues = new Array ();
// var comboText = new Array ();
//
// Fill in arrays for dynamic use

// static definitions
var comboValues = [10, 20, 30];
var comboText = ['String 10', 'String 20', 'String 30'];

// initial text
objCombo.setControlText("default text");
// initial value of combo
var comboValue = 0;

// define original dropdown text strings
objCombo.setItemText(comboText);
objCombo.setItemCount(comboText.length);

// make the combo read-only so user can't fill in random text
objCombo.getContent('box/text').setAttribute('readonly', true);

objCombo.onCurrentItemChanged = function (index) {
comboValue = comboValues[index];
this.setControlText(comboText[index]);
this.hidePopup();
}

// css elements:
//
// #objCombo {width: 200px;}
// #objCombo-popup {width: 200px;}
//

document.write(objCombo);
Roger
February 22,

This topic is archived.

See also:


Back to support forum