Webbrowser MSHTML Problem

Posted on 2002-07-03
Last Modified: 2012-06-21
One step forward and 2 back.  I normally mainly do server side coding but I was asked to convert a Server based IIS DLL to run as a "detached from the internet" client. It all works well except:

getAttribute("Value") does not seem to work for <select> elements.

To reproduce the problem:

1) Create a new Standared EXE project.
2) Set a Project component: Microsoft Internet Controls.
3) Set a Project Reference to: Microsoft HTML Object Library.
4) Create a Webbrowser1 control on your form.

Paste the following code & run.

The click on the Submit button.

The code marked with ## does not return the value of the select box.

How can I change the code to find the the Select element value?

------Form Code Starts Here----------
Option Explicit

Dim WithEvents HFORM As MSHTML.HTMLFormElement

Private Sub Form_Load()


' Place a dummy page in the browser
WebBroweser1.Navigate "about:blank"

Dim m$

' create a HTML form with a Select box, Text Input box and submit button.
m$ = "<HTML><BODY><Form ID=""MyForm"" Name=""PRB"" Action="""" Method=""Post"">" _
    + "Change the select box to Item 1 then click Submit<BR>Select Box<Select ID=""IDV1"" Name=""V1"">" _
    + "<Option><Option>Item 1<Option Selected>Item 2</Select>" _
    + "<Input ID=""IDV2"" Type=""Text"" Name=""V2"" Value=""This value is ok"">" _
    + "<Input ID=""IDV3"" Type=""Submit"" Name=""V3"" Value=""Submit"">" _
    + "</Form></Body></html>"
' load the html into the browser
WebBroweser1.Document.write m$

' link the form element to that the Submit button can be trapped.

Set HFORM = WebBroweser1.Document.getElementById("MyForm")
End Sub

Private Function HFORM_onsubmit() As Boolean


' display the data from the form

Dim m$
m$ = "The values found were as follows:" + vbCrLf

Set SELEL = WebBroweser1.Document.getElementById("IDV1")

' The following line fails to get the value
' of the select box
m$ = m$ + "IDV1=" + SELEL.getAttribute("Value") + " Why is this value empty?" + vbCrLf ' ## This is strange
Set HELEMENT = WebBroweser1.Document.getElementById("IDV2")
m$ = m$ + "IDV2=" + HELEMENT.getAttribute("Value") + vbCrLf
Set HELEMENT = WebBroweser1.Document.getElementById("IDV3")
m$ = m$ + "IDV3=" + HELEMENT.getAttribute("Value") + vbCrLf
Set HELEMENT = Nothing
HFORM_onsubmit = False
MsgBox m$

End Function

Question by:inthedark
  • 2
LVL 28

Accepted Solution

AzraSound earned 200 total points
ID: 7127622
In normal script, you would actually get something like:

LVL 17

Author Comment

ID: 7127928
Thanks, it works:

m$ = m$ + "IDV1=" + SELEL.Options(SELEL.selectedIndex).Text
LVL 17

Author Comment

ID: 7128268
I am very new to DHTML, but I have done quite a bit of JavaScript.  I realy found that it was hard debugging the scripts, compared to VB. AzraSound what tool do you use for debugging your DHTML

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question