Search code examples
silverlightwindows-phone-7comboboxbrowserselectedindex

How can I change the ComboBox "selectedIndex" on WebBrowser on Silverlight for Windows Phone?


In the WebBrowser there is this page (http://gttweb.5t.torino.it/gtt/en/percorsi/percorsi-ricerca.jsp) and there is the "destinationCity" ComboBox. In VB.NET I use:

Dim DestinationComboBox As HtmlElement = MainWebBrowser.Document.All.Item("destinationCity")
DestinationComboBox.SetAttribute("selectedindex", 1)

to change the ComboBox selectedIndex, but in Silverlight (in this WebBrowser) there's only the InvokeScript function.. How can I change the selectedIndex using InvokeScript()? I've tried

InvokeScript("eval", "document.getElementById('destinationCity').selectedindex = 4")

But it doesn't work.. Help please!


Solution

  • If you use Chrome Developer Tools, or FireBug to execute the following JavaScript against the given page, you will find that it does not work in a desktop browser:

    document.getElementById('destinationCity').selectedindex = 4
    

    JavaScript, and the selectedIndex property are case sensitive. The following works:

    document.getElementById('destinationCity').selectedIndex = 4