3.0 beta 2

v2.0 Combo Control - Value vs Text

I need help with the STANDALONE combo control in V2.0 Standard (final).

I want to replace a standard html dropdown with the AW combo control. In the standard control is have items such as:

<option value="5" >123 Main St.</option>

The item has a value AND text associated with it. The dropdown keeps up with the "selectedItem" offset and I can query the value using something like

With the AW combo I don't know how to associate a value with the text of each item. I set the text with setItemText and then tried using:

myAWcombo.setItemValue(["7", "12", "19", "20"]);

This doesn't cause an error but doesn't seem to help either. A call to myAWcombo.getControlValue() later will return the text instead of the value.

I also can't find a way to tell the offset of the selected item. If I could then I would just pull the value out of a JS array directly.

Does anyone know how to do this?
Rob Francis
February 26,
Did you try with .... myAWcombo.getItemValue(index) ??
Note "Item" for list and "Control" for Input part, or ..do you need the Value for the Control also ??
February 26,
Hi Carlos,

myAWcombo.getItemValue(index) is a valid command but I don't have a value to use for "index"

I figured out a possible source code (or override) change that will work.

I can use:
myAWCombo.onCurrentItemChanged = function(i){ 
    var value = this.getItemValue(i);

    var text = this.getItemText(i);


    var e = this.getContent("box/text").element();
    if (AW.safari) {
      e.innerHTML = text;
    else {
      e.value = text;
    e = null;

The only lines I really added are:
var value = this.getItemValue(i);

The rest of the lines I copied from the same function in the source code at:

Now, I have 3 choices ...
1) edit the source in combo.js so it is supported for all combos (bad thing is remembering to change the source code each release)
2) use the code like above in my html file to override the function on each use (bad part is source code might change and I will miss out)
3) Talk Alex into making the source code change in the official release.

I'm hoping option 3 is the anwser but I'm not sure of his intent for the control.

Anyway, with the change above in the control will support obj.getControlValue() in addition to getControlText. I gives me what I need.
Rob Francis
February 26,
BTW, I meant to ask...

If I create a function in my html like:
myAWCombo.onCurrentItemChanged = function(i){  

then the same function in combo.js is NOT called. Mine replaces it.

Is there a way for me to execute my override code first but then have it still execute the default code?
Rob Francis
February 26,
to set values

obj.setItemValue(["id", "name", "date"]);
obj.setItemText(["Number", "Account", "Operation Date"]);

and to know the selected value, use
var_selected_value = obj.getItemValue(obj.getSelectedItems());
March 9,
Hi Javier ... many thanks!

The part I was missing is getSelectedItems. Now that I know about it I will use your solution where I don't have to patch the source.
Rob Francis
March 9,
OK, can you Help me? But I need it quick, because I had to finish my work today and this is the only thing, that does not work !!!

I have code like this for every combo:

function combo_setup($dataset){
    $result_text = '[';
    $result_value = '[';
    $num_rows = mysql_num_rows($dataset);
    $i = 1;
    while ($row = @mysql_fetch_array($dataset)) 
        $result_text .= '"'.$row['param_value']." - ".$row['param_text'].'"';
        $result_value .= '"'.$row['param_value'].'"';

        if($i < $num_rows)
            $result_text .= ',';
            $result_value .= ',';
    echo 'comboText = '.$result_text.'];'."\n\t";
    echo 'comboValue = '.$result_value.'];'."\n\t";
    echo 'comboItems = '.$num_rows.';'."\n\t";

var comboClientDistrict = new AW.UI.Combo;
    comboClientDistrict.setPosition(651, 81);
    comboClientDistrict.setSize(250, 20);
    $dataset = mysql_query("Select town AS param_text, sign AS param_value From WAIS_okres");							

    comboClientDistrict.getContent("box/text").setAttribute("readonly", true);
    comboClientDistrict.onControlEditStarted = function(){
        this.getContent("box/text").element().contentEditable = false;

So in final efect i set properities like this:

//Got from PHP script:
comboText = ["1 - first","2 - second","3 - third","4 - fourth"];
comboValue = ["1","2","3","4"];
comboItems = 4;

//Added to the object:

But this is what i get:

comboCompany.getSelectedItems() // = 1
comboCompany.getItemText(comboCompany.getSelectedItems()) // = 1 - First
comboCompany.getItemValue(comboCompany.getSelectedItems()) // = undefined !!!!

WHAY THAT DOES NOT WORK ??? Why the ItemValue is allways UNDEFINED???
June 2,
Maybe comboValue gets overwritten somewhere in the middle? I tried to replicate it, but everything works fine in my case :-(

var obj = new AW.UI.Combo;

    var comboText = ["1 - first","2 - second","3 - third","4 - fourth"];
    var comboValue = ["1","2","3","4"];
    var comboItems = 4;



    obj.onControlValidated = function(){

Alex (ActiveWidgets)
June 2,
Hope it is not due to usage of Prototype, but the Text item is returnet the way it has to, so I do not know why... The script above creates more combos in the form, but all behaves the same vay. Text is OK, but the Value is undefined.

The only workaround i can do now is the usage of text, that in this case always starts with the value part (like in the expample above). So I'll have to substring it from Text... :(

But any clue making me find the reason for this behaviour is appreciated...
June 3,

This topic is archived.

See also:

Back to support forum


Version 2

Looking for AW 2.6 ?
The old site is here.