Solved

Webbrowser MSHTML Problem

Posted on 2002-07-03
3
231 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
[X]
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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

628 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