javascriptwindows-mobileie-mobile

How to Add options to <SELECT>, in IE Windows Mobile 5


Trying to programmatically add options to a SELECT drop down in IE Windows Mobile.

Because this is IE Windows Mobile 5, most solutions involving getElementID do not function, so I have had to resort to more plain vanilla HTML /Java script, the example below works fine in IE 6 and FF , but fails with "Object doesn't support this property or method" in Windows Mobile 5

function insertBarcodes()
{
val = document.form1.barcode.value ;
i = document.form1.blist.length;
myNewOption = new Option(val , val ); 
document.form1.blist.options[document.form1.blist.length] =myNewOption ; 
 }
 updateCount();

}

Any ideas?


Solution

  • Found the answer here:

    First I looked at the official reference source here: http://msdn.microsoft.com/en-us/library/bb159677.aspx

    I noted that there is an add method for the selectObj, so I tried it and it worked..

    here's the working code,

    function AddSelectOption(selectObj, text, value, isSelected){
      if(selectObj != null && selectObj.options != null){
        var newOpt = new Option('Hello','Hello'); //create the option object
        selectObj.add(newOpt); //it's the .add(option) method
      }
    }
    

    Thanks to all