?
Solved

vba interacting with HTMLselectelement with onchange property

Posted on 2007-10-09
7
Medium Priority
?
2,534 Views
Last Modified: 2010-05-18
I am trying to automate entries to a web page and I am getting stuck on a select element that contains an onchange property.  When a selection is made by clicking on one of the option elements, new information is added to the webpage.  When I try to automate this selection using vba, the onchange property does not seem to be activated.

Here is the source code for the HTMLselectelement I am trying to interact with.
<select id="rcat" name="rcat"
                 onchange="rr_changeHandler(this);">
          <option value="oef">Element Forces
          <option value="gpf">Grid Point Forces
          <option value="balance">Grid Point Force Balance
          <option value="oelop">Element-oriented Forces
          <option value="disp">Displacement Vectors
          <option value="maxmin">Envelope Loads
          <option value="stress">Envelope Stresses
          <option value="maxd">Envelope Displacements
          <option value="bdf">Bulk Data
          <option value="compare">Comparison (Ratios)
       </select></td>

I can select any option here, the only problem i have is triggering the onchange.
0
Comment
Question by:mbbarclay
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 20047546
this works for me

<html>
<head>
 <script language="JavaScript">
   function rr_changeHandler()
   {
    alert(rcat.options(rcat.selectedIndex).text);
 
   }

 </script>

</head>
<body>
<select id="rcat" name="rcat"
                 onchange="rr_changeHandler()">
          <option value="oef">Element Forces
          <option value="gpf">Grid Point Forces
          <option value="balance">Grid Point Force Balance
          <option value="oelop">Element-oriented Forces
          <option value="disp">Displacement Vectors
          <option value="maxmin">Envelope Loads
          <option value="stress">Envelope Stresses
          <option value="maxd">Envelope Displacements
          <option value="bdf">Bulk Data
          <option value="compare">Comparison (Ratios)
       </select>
</body>
</html>
0
 

Author Comment

by:mbbarclay
ID: 20049416
Thanks for the response, but I am trying to automate the selection from this webpage using VBA.  I have no control over how the HTML is written for the webpage.  

This is what i have so far:

  Dim IE As SHDocVw.InternetExplorer
  Dim hCol As MSHTML.IHTMLElementCollection
  Dim hSel As MSHTML.HTMLSelectElement

Set hCol = IE.document.getElementsByTagName("SELECT")

For Each hSel In hCol
  If hSel.Name = "rcat" Then
  hSel.selectedIndex = 6
   Exit For
  End If
  Next hSel

This will select the option element that I need, but I cannot figure out how to interact with the onchange call.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 20049581
you may want to change

Dim hSel As MSHTML.HTMLSelectElement

to declare on global as

Private WithEvents hSel As MSHTML.HTMLSelectElement


Private Sub hSel_onchange()

End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 20049654
It is not been tested

Private WithEvents hSel1 As MSHTML.HTMLSelectElement

Private Sub hSel1_onchange()

End Sub

Dim IE As SHDocVw.InternetExplorer
  Dim hCol As MSHTML.IHTMLElementCollection
  Dim hSel As MSHTML.HTMLSelectElement

Set hCol = IE.document.getElementsByTagName("SELECT")

For Each hSel In hCol
  If hSel.Name = "rcat" Then
  hSel.selectedIndex = 6
set hSel1 = hSel
   Exit For
  End If
  Next hSel
0
 

Author Comment

by:mbbarclay
ID: 20051610
i figure it out.  I had to add a fireevent to the selectelement

Dim IE As SHDocVw.InternetExplorer
  Dim hCol As MSHTML.IHTMLElementCollection
  Dim hSel As MSHTML.HTMLSelectElement

Set hCol = IE.document.getElementsByTagName("SELECT")

For Each hSel In hCol
  If hSel.Name = "rcat" Then
  hSel.selectedIndex = 6
  hSel.FireEvent "onchange", hSel
   Exit For
  End If
  Next hSel
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 21447663
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

Technology Partners: 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

Make the most of your online learning experience.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

839 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