dropdownlist web input from client

Fremus

Active member
Joined
Jun 9, 2007
Messages
42
Programming Experience
Beginner
hi

i've got a little problem...

well i created an application that will fill a textfile from a web dropdown list..

VB.NET:
Dim test As String = WebBrowser1.Document.GetElementById("TheID").Children.Item(i).OuterText

now i need to select an item from the dropdown list (same one) programmatically... is that possible?

Thanks in advance

Fremus :)
 
Either set 'selectedIndex' property of the dropdown, or set 'selected' property of the option item to True.
VB.NET:
Dim el As HtmlElement = Me.WebBrowser1.Document.GetElementById("TheID")
el.SetAttribute("selectedIndex", 2)
'or
'el.Children(2).SetAttribute("selected", True)
 
Hi..

Thanks JohnH, for the code... it worked good!

i've got another question though...

The scenario of the web page is that one give a value to the 1st drop down list and another drop down list will fill up according to what was selected from the 1st one.

so now i'm programmatically entering (selecting) the value of the first drop down list.. .but the second drop down is not getting filled according :/

any ideas?! i'm going to go through it myself again

Thanks in advance
 
Since you call the Select tag a "dropdownlist" I presume the webpage is served from ASP.Net. What you describe "another drop down list will fill up according" is something that happens in server code when page postbacks, not when you manually change a page element property at client side. There are several ways to force the postback so the server application may do its job, what I would prefer:
VB.NET:
el.InvokeMember("onchange")
or
VB.NET:
Me.WebBrowser1.Document.Forms(0).InvokeMember("submit")
VB.NET:
Me.WebBrowser1.Document.InvokeScript("__doPostBack", New Object() {"TheID", ""})
or probably other methods too :rolleyes:
 
Back
Top