If you look at the source code for the html you can see the combobox has an id. However when i run a loop through all hte elements on the page in vb.net it comes up as a blank instead of the id thats clearly defined. I'm thinking it has something to do with the javascript giving it a dynamic id. Anyway. I need to set this box after the page has loaded in a webbrowser object. Please help. Its driving me crazy!
<input type="hidden" name="wlw-select_key:{actionForm.dobMonth}OldValue" value="true">"
<select name="wlw-select_key:{actionForm.dobMonth}" id="dobMonth" class="dobMonth"><option" value="">Month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option></select>
<script language="JavaScript" type="text/JavaScript">
<!--
netui_tagIdNameMap.dobMonth="wlw-select_key:{actionForm.dobMonth}"
-->
</script>
*My Source Code Attemps *** WebBrowser1.Document.GetElementById("dobMonth").SetAttribute("selectedtext", "March") - dosent work
Dim el As HtmlElement = WebBrowser1.Document.All("wlw-select_key:{actionForm.dobMonth}")
Dim elCol As HtmlElementCollection = el.GetElementsByTagName("option")
Dim X As Integer = 0
For Each op As HtmlElement In elCol
If op.InnerText = "March?" Then
el.SetAttribute("selectedIndex", X.ToString())
Exit For
End If
X += 1
Next
- that didnt work either
So i'm really out of options. Any ideas. I did some research on the javascript r开发者_StackOverflow社区eference but didnt turn out much useful. Thanks in advance!
as I remember, the name and id attributes are limited in the characters they can contain. curly-braces are probably not allowed. not sure if that's your problem or not, but it's the first thing that popped into mind... I'll look into it some more.
[much later...] OK, this works, but I hacked out a bunch of stuff, and it may not be quite what you're looking for:
<select name="dobMonth" id="dobMonth" class="dobMonth"><option value="">Month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<script type="text/javascript">
document.getElementById("dobMonth").selectedIndex = 3;
</script>
You had a stray double-quote in your first option tag, which may have been part of the problem. But fixing that didn't allow the vbscript to work in my browser. I haven't done VBscript since the mid-90s so I switched to javascript. In any case it ought to give you a basis for further development, I hope!
[later] This code will set the option by text string. I tested under Firefox, it ought to work in IE also:
<script type="text/javascript">
function setSelected(month) {
var select = document.getElementById("dobMonth");
var options = select.getElementsByTagName("option");
for (var i = 0; i < options.length; i++) {
if (options[i].childNodes[0].nodeValue == month) {
select.selectedIndex = i;
break;
}
}
}
setSelected("March");
</script>
精彩评论