Solved

Webbrowser MSHTML Problem

Posted on 2002-07-03
3
212 Views
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()

DoEvents

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

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$
DoEvents

' 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

Dim HELEMENT As MSHTML.HTMLGenericElement
Dim SELEL As MSHTML.HTMLSelectElement

' 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




0
Comment
Question by:inthedark
  • 2
3 Comments
 
LVL 28

Accepted Solution

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

SELEL.options[SELEL.selectedIndex].text
0
 
LVL 17

Author Comment

by:inthedark
ID: 7127928
Thanks, it works:

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

Author Comment

by:inthedark
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now