• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2414
  • Last Modified:

How do I fire an onChnage even in a twebbrowser - Delphi

Hi,

I'm loading a webpage into a twebbrowser in delphi

the webpage contains a dropdown menu, i can select the menu item i want but it wont fire the OnChange event.

I've tried to use the HTMLWindow.execScript('yourfunctioname()', 'JavaScript');  method

but it always throws back errors (delphi could not complete the operation due to error 80020101) I think it might be an AJAX issue.

I was trying to get around it by using the OleVariant(yourIHTMLElement).FireEvent('onchange') ; method but im not sure how to use it, can anyone provide an example?

the only other way would be to simulate a mouse click on the dropdown?


here's the dropdown im trying to change:


many thanks

Stu

<select align="left" id="carrierNameDropDown_UNSHIPPEDITEMS" onChange="MYO.ES.OtherCarrierToggle (this, 'UNSHIPPEDITEMS' )">
          <option value="0"  selected="1" >Select</option>
              <option value="Chronopost"  >Chronopost</option>
              <option value="City Link"  >City Link</option>
              <option value="DHL"  >DHL</option>
              <option value="DPD"  >DPD</option>
              <option value="Deutsche Post"  >Deutsche Post</option>
              <option value="Fastway"  >Fastway</option>
              <option value="FedEx"  >FedEx</option>
              <option value="GLS"  >GLS</option>
              <option value="GO!"  >GO!</option>
              <option value="Hermes Logistik Gruppe"  >Hermes Logistik Gruppe</option>
              <option value="La Poste"  >La Poste</option>
              <option value="Parcelforce"  >Parcelforce</option>
              <option value="Parcelnet"  >Parcelnet</option>
              <option value="Poste Italiane"  >Poste Italiane</option>
              <option value="Royal Mail"  >Royal Mail</option>
              <option value="SDA"  >SDA</option>
              <option value="Smartmail"  >Smartmail</option>
              <option value="TNT"  >TNT</option>
              <option value="Target"  >Target</option>
              <option value="UPS"  >UPS</option>
              <option value="Yodel"  >Yodel</option>

          <option value="Other">
              Specify carrier:
          </option>
        </select>

Open in new window

1
stuayre
Asked:
stuayre
  • 3
  • 2
1 Solution
 
kumaresan2011Commented:
hi

some solutions for you

try it

by
kumaresan
uses 
  MSHTML;

procedure TBrowserPageIE.Test;
var
  doc : IHTMLDocument3;
  el  : IHTMLElement;
  v   : OleVariant;
begin
  if FBrowser.Document <> nil then begin
    if FBrowser.Document.QueryInterface(IHTMLDocument3,doc) = S_OK then begin
      el := doc.getElementById('carrierNameDropDown_UNSHIPPEDITEMS');

      if el <> nil then begin
        (el as IHTMLSelectElement).value := 'UPS';
        (el as IHTMLElement3).FireEvent('onchange', v);
      end;
    end;
  end;
end;

Open in new window

0
 
kumaresan2011Commented:
hi

some useful links for u

http://www.delphidabbler.com/articles?article=21

by
kumaresan
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
kumaresan2011Commented:
hi

look this, it may be help ful to you

procedure TForm1.Button3Click(Sender: TObject);
var  Doc:        IHTMLDocument2;
     HTMLWindow: IHTMLWindow2; // parent window of current HTML document
begin

  with form1 do
  begin
     Doc := WebBrowser1.Document as IHTMLDocument2;
     if not Assigned(Doc) then Exit;
     HTMLWindow := Doc.parentWindow;
     if not Assigned(HTMLWindow) then Exit;
     HTMLWindow.execScript('_myoES_OtherCarrierToggle(changecolour)', 'Javascript');
  end;

end;
Unit1.dfm
Unit1.pas
Article21.dpr
FmDemo.dfm
FmDemo.pas
Test.html
0
 
stuayreAuthor Commented:
here's the answer:

if EmbeddedWB1.Document <> nil then begin
if EmbeddedWB1.Document.QueryInterface(IHTMLDocument3,docb) = S_OK then begin
elb := docb.getElementById('carrierNameDropDown_UNSHIPPEDITEMS');
if elb <> nil then begin
(elb as IHTMLSelectElement).value := 'Parcelforce';
OleVariant (elb as IHTMLElement). FireEvent ('onchange');
end;

Open in new window

0
 
stuayreAuthor Commented:
this one works
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now