[RESOLVED] [2005] webBrowser selects
alright, I've downloaded Kleinma's code, studied over it, searched the forums, I don't see a way to set a combo box, the code in the codebank shows getting the value it is currently set to, which I had figured out.
Here's the section of the form I want to auto-fill/adjust:
Code:
<SELECT name=const_code>
<OPTION value=" ">Select Construction Code</OPTION>
<OPTION value=1>Proposed Construction</OPTION>
<OPTION value=2>Substantial Rehabilitation</OPTION>
<OPTION value=3>Under Construction</OPTION>
<OPTION value=4 selected>Existing Construction</OPTION>
<OPTION value=5>New Construction (Less than 1 Year)</OPTION>
</SELECT>
And I get the value using the following:
Code:
Me.WebBrowser1.Document.Forms("aac_form").All("const_code").GetAttribute("value")
Which doesn't give me the text, just the integer value, but I don't believe I actually need the text for my purposes, just the values anyhow.
Here's what I thought would work:
Code:
Me.WebBrowser1.Document.Forms("aac_form").All("const_code").SetAttribute("value",2)
But unlike the working textbox fill ins I have, this doesn't appear to do anything, not even throwing an exception.
Anyone know how to do this?
Re: [2005] webBrowser selects
You need to set the "selected" attribute of the child node in theat select node. For example, if you want to select the 3rd option (which has value=2), you do:
Code:
Me.WebBrowser1.Document.Forms("aac_form").All("const_code").Children(2).SetAttribute("selected", "selected")
Re: [2005] webBrowser selects
Thank you that worked, now... in your code at the 2
Children(2)
what would be the 'name' if I wanted to go with the other overload?
Re: [2005] webBrowser selects
No, if you look at the html, you see that the option nodes do not have any name or id. That number 2 is the index of the child node. If you want to pick and option but you only know the display text or the value and not the index of the node, you have to loop thru the Children htmlElementCollection and test each element's value/innertext against your known value to find the right element. Once found, you set it "selected" attribute as shown.