Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Webbrowser MSHTML Problem

Posted on 2002-07-03
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 28

Accepted Solution

AzraSound earned 800 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction While answering a recent question ( 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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses

722 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